{"id":13746548,"url":"https://github.com/wix-incubator/wix-embedded-mysql","last_synced_at":"2025-05-09T07:30:45.995Z","repository":{"id":21111235,"uuid":"24411771","full_name":"wix-incubator/wix-embedded-mysql","owner":"wix-incubator","description":"embedded mysql based on https://github.com/flapdoodle-oss/de.flapdoodle.embed.process","archived":true,"fork":false,"pushed_at":"2022-02-22T15:42:46.000Z","size":946,"stargazers_count":384,"open_issues_count":38,"forks_count":81,"subscribers_count":353,"default_branch":"master","last_synced_at":"2025-04-21T09:55:37.158Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wix-incubator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-24T11:07:38.000Z","updated_at":"2025-02-20T03:17:25.000Z","dependencies_parsed_at":"2022-08-25T12:41:04.590Z","dependency_job_id":null,"html_url":"https://github.com/wix-incubator/wix-embedded-mysql","commit_stats":null,"previous_names":["wix/wix-embedded-mysql"],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fwix-embedded-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fwix-embedded-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fwix-embedded-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fwix-embedded-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wix-incubator","download_url":"https://codeload.github.com/wix-incubator/wix-embedded-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253209264,"owners_count":21871622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T06:00:55.366Z","updated_at":"2025-05-09T07:30:45.351Z","avatar_url":"https://github.com/wix-incubator.png","language":"Java","funding_links":[],"categories":["Java","测试"],"sub_categories":[],"readme":"# Wix Embedded MySql [![Build Status (Travis: Linux/OSX)](https://img.shields.io/travis/wix/wix-embedded-mysql/master.svg?label=linux%2FOSX%20build)](https://travis-ci.org/wix/wix-embedded-mysql) [![Build Status (AppVeyor: Windows)](https://img.shields.io/appveyor/ci/viliusl/wix-embedded-mysql/master.svg?label=windows%20build)](https://ci.appveyor.com/project/viliusl/wix-embedded-mysql) [![Maven Central](https://img.shields.io/maven-central/v/com.wix/wix-embedded-mysql.svg)](http://mvnrepository.com/artifact/com.wix/wix-embedded-mysql)\n\n**[DEPRECATED]** - mostly due to substantial changes in packaging between version changes and emergence of new and better ways to run embedded mysql. Please check-out [Testcontainers](https://www.testcontainers.org/) as a better alternative.\n\n## Why?\n- Your tests can run on production-like environment: match version, encoding, timezone, database/schema/user settings;\n- Its easy, much easier than installing right version by hand;\n- You can use different versions/configuration per project without any local set-up;\n- Supports multiple platforms: Windows, Linux and OSX;\n- Provides constantly updated multiple versions of MySql - 5.5, 5.6, 5.7, 8.0;\n- Testing matrix for all supported OSes (x86/x64) and versions (5.5, 5.6, 5.7, 8.0).\n\n## Maven\nAdd dependency to your pom.xml:\n\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.wix\u003c/groupId\u003e\n        \u003cartifactId\u003ewix-embedded-mysql\u003c/artifactId\u003e\n        \u003cversion\u003ex.y.z\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n```\n\n## Usage\n - [Basic usage example](#basic-usage-example)\n - [Customizing mysqld settings](#customizing-mysqld-settings)\n - [Customizing download settings](#customizing-download-settings)\n - [Multiple schemas/databases](multiple-schemasdatabases)\n - [Resetting schemas between tests](#resetting-schemas-between-tests)\n - [Using in a hermetic environment](#using-in-a-hermetic-environment)\n\n### Basic usage example\n\nYou can start an embedded mysql with defaults and a single schema:\n\n```java\nimport com.wix.mysql.EmbeddedMysql;\n\nimport static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;\nimport static com.wix.mysql.ScriptResolver.classPathScript;\nimport static com.wix.mysql.distribution.Version.v5_7_latest;\n\nEmbeddedMysql mysqld = anEmbeddedMysql(v5_7_latest)\n    .addSchema(\"aschema\", classPathScript(\"db/001_init.sql\"))\n    .start();\n\n//do work\n\nmysqld.stop(); //optional, as there is a shutdown hook\n```\n\n### Customizing mysqld settings\n\nIf you need more control in configuring embeded mysql instance, you can use [MysqldConfig](wix-embedded-mysql/src/main/java/com/wix/mysql/config/MysqldConfig.java) builder:\n\n```java\nimport com.wix.mysql.config.MysqldConfig;\nimport com.wix.mysql.EmbeddedMysql;\nimport static com.wix.mysql.ScriptResolver;\n\nimport java.util.concurrent.TimeUnit;\n\nimport static com.wix.mysql.config.MysqldConfig.aMysqldConfig;\nimport static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;\nimport static com.wix.mysql.distribution.Version.v5_6_23;\nimport static com.wix.mysql.config.Charset.UTF8;\n\nMysqldConfig config = aMysqldConfig(v5_6_23)\n    .withCharset(UTF8)\n    .withPort(2215)\n    .withUser(\"differentUser\", \"anotherPassword\")\n    .withTimeZone(\"Europe/Vilnius\")\n    .withTimeout(2, TimeUnit.MINUTES)\n    .withServerVariable(\"max_connect_errors\", 666)\n    .build();\n\nEmbeddedMysql mysqld = anEmbeddedMysql(config)\n    .addSchema(\"aschema\", ScriptResolver.classPathScript(\"db/001_init.sql\"))\n    .addSchema(\"aschema2\", ScriptResolver.classPathScripts(\"db/*.sql\"))\n    .start();\n\n//do work\n\nmysqld.stop(); //optional, as there is a shutdown hook\n```\n\n### Customizing download settings\n\nIn addition you can control additional settings of embedded mysql by providing configs that have base type of [AdditionalConfig](wix-embedded-mysql/src/main/java/com/wix/mysql/config/AdditionalConfig.java) by providing those to `anEmbeddedMysql` builder:\n\n```java\nimport com.wix.mysql.EmbeddedMysql;\n\nimport static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;\nimport static com.wix.mysql.ScriptResolver.classPathScript;\nimport static com.wix.mysql.distribution.Version.v5_7_latest;\nimport static com.wix.mysql.config.DownloadConfig.aDownloadConfig;\nimport static com.wix.mysql.config.ProxyFactory.aHttpProxy;\n\nDownloadConfig downloadConfig = aDownloadConfig()\n    .withProxy(aHttpProxy(\"remote.host\", 8080))\n    .withCacheDir(System.getProperty(\"java.io.tmpdir\"))\n    .build();\n\nEmbeddedMysql mysqld = anEmbeddedMysql(v5_7_latest, downloadConfig)\n    .addSchema(\"aschema\", classPathScript(\"db/001_init.sql\"))\n    .start();\n\n//do work\n\nmysqld.stop(); //optional, as there is a shutdown hook\n```\n\n### Multiple schemas/databases\n\nEmbeddedMysql supports multiple schemas and additional configuration options provided via [SchemaConfig](wix-embedded-mysql/src/main/java/com/wix/mysql/config/SchemaConfig.java) builder:\n\n```java\nimport com.wix.mysql.EmbeddedMysql;\nimport com.wix.mysql.config.SchemaConfig;\n\nimport static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;\nimport static com.wix.mysql.ScriptResolver.classPathScript;\nimport static com.wix.mysql.ScriptResolver.classPathScripts;\nimport static com.wix.mysql.config.SchemaConfig.aSchemaConfig;\nimport static com.wix.mysql.config.Charset.LATIN1;\nimport static com.wix.mysql.distribution.Version.v5_6_latest;\n\nSchemaConfig schema = aSchemaConfig(\"aSchema\")\n    .withScripts(classPathScript(\"db/001_init.sql\"))\n    .withCharset(LATIN1)\n    .build();\n\nEmbeddedMysql mysqld = anEmbeddedMysql(v5_6_latest)\n    .addSchema(schema)\n    .addSchema(\"aschema2\", classPathScripts(\"db/*.sql\"))\n    .start();\n\n//do work\n\nmysqld.stop(); //optional, as there is a shutdown hook\n```\n\n### Resetting schemas between tests\n\nIt is intended to be started once per test-suite, but you can reset schema in between tests which recreates database and applies provided migrations:\n\n```java\nimport com.wix.mysql.EmbeddedMysql;\n\nimport static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;\nimport static com.wix.mysql.ScriptResolver.classPathScript;\nimport static com.wix.mysql.distribution.Version.v5_6_latest;\n\nEmbeddedMysql mysqld = anEmbeddedMysql(v5_6_latest)\n    .addSchema(\"aschema\", classPathScript(\"db/001_init.sql\"))\n    .start();\n\n//do work\n\nmysqld.reloadSchema(\"aschema\", classPathScript(\"db/001_init.sql\"));\n\n//continue on doing work\n\nmysqld.stop(); //optional, as there is a shutdown hook\n```\n\nSource for examples can be found [here](https://github.com/wix/wix-embedded-mysql/blob/master/wix-embedded-mysql/src/test/scala/com/wix/mysql/JavaUsageExamplesTest.java)\n\n### Using in a hermetic environment\n\nSome build tools strongly encourages you to have tests which are isolated from the internet.  \nTo support such a use-case you can use the `wix-embedded-mysql-download-and-extract` utility.  \nIt produces a runnable jar (`wix-embedded-mysql-download-and-extract-[[VERSION]]-jar-with-dependencies.jar`) which you can call with `java -jar wix-embedded-mysql-download-and-extract-[[VERSION]]-jar-with-dependencies.jar $downloadDir $majorVersion $minorVersion` and it will download and extract the needed installer for you.  \nAdditionally you should pass the download directory to your test so that it can configure your `DownloadConfig#withCacheDir` to use that directory instead of downloading it from the internet.\n\n# Dependencies\nBuild on top of [de.flapdoodle.embed.process](https://github.com/flapdoodle-oss/de.flapdoodle.embed.process)\n\n# How it works\n - After detecting current platform and requested version, Wix Embedded MySql will download the correct version from [dev.mysql.com](https://dev.mysql.com/downloads/) and extract needed files to local folder. Note that this is a **one-time** action, where subsequent invocations use pre-downloaded/pre-extracted cached package.\n - Upon execution needed files are being copied into **target** folder, database created, service started and post-configuration (user, schema, etc.) performed.\n - On jvm shutdown mysqld process is stopped and temporary files cleaned-up.\n\n# Tested on\n - latest OSX;\n - ubuntu precise 32/64;\n - windows 2012;\n\n# Known issues\n - starting version 5.7.18, Microsoft Visual C++ 2013 Redistributable Package needs to be pre-installed on windows.\n - starting version 5.5.10 `libaio1.so` needs to be pre-installed on linux, but that is not the case for some linux distributions. Proper error is emitted if it's missing and you have to install it manually (ex. ubuntu):\n\n```bash\nsudo apt-get install libaio1\n```\n\n - if tests are failing with 'Broken pipe' or 'Stream closed' exceptions on linux, you might be missing `libncurses5`:\n\n```bash\nsudo apt-get install libncurses5\n```\n\n - starting version 8.x.x more libraries from underlying os are required. Known list:\n ```\n libnuma1 libssl1.0 libcrypto++6\n ```\n\n# License\nUse of this source code is governed by a [BSD License](LICENSE.md), which basically means you can use and modify it freely.\n\n# Similar project\n[MariaDB4j](https://github.com/vorburger/MariaDB4j) is an unrelated similar project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fwix-embedded-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwix-incubator%2Fwix-embedded-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fwix-embedded-mysql/lists"}