mysql embedded is a library that provides a method to run real MySql in integration tests; users can implement embedded MySQL by integrating the jar package without installing Mysql. Perform database operations such as additions, deletions, modifications, and queries.
Usage of EmbeddedMySql
The Embedded MySql library provides a way to run real MySql in integration tests. We can implement embedded MySQL by integrating this jar package. There is no need to install Mysql to perform database additions, deletions, modifications, and other related operations. First introduce the maven dependency<dependency> <groupId>com.wix</groupId> <artifactId>wix-embedded-mysql</artifactId> <version>4.6.1</version> <scope>test</scope> </dependency>
import com.wix.mysql.config.MysqldConfig;import com.wix.mysql.EmbeddedMysql;import static com.wix.mysql.ScriptResolver;import java.util.concurrent.TimeUnit;import static com.wix.mysql.config.MysqldConfig.aMysqldConfig;import static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;import static com.wix.mysql.distribution.Version.v5_6_23;import static com.wix.mysql.config.Charset.UTF8;public class EmbeddedMysqlConfig { private EmbeddedMysql mysqld; public void launchDb(){ //mysql版本 MysqldConfig config = aMysqldConfig(v5_6_23) .withCharset(UTF8) //端口号 .withPort(13306) //用户名密码 .withUser("root", "123456") //时区 .withTimeZone("Asia/Shanghai") .withTimeout(2, TimeUnit.MINUTES) .withServerVariable("max_connect_errors", 666) .build(); mysqld = anEmbeddedMysql(config) //初始化数据表结构 .addSchema("aschema", ScriptResolver.classPathScript("db/001_init.sql")) .addSchema("aschema2", ScriptResolver.classPathScripts("db/*.sql")) .start(); } public void stopDb(){ mysqld.stop(); }}
mysql video tutorial]
The above is the detailed content of what is mysql embedded. For more information, please follow other related articles on the PHP Chinese website!