what is mysql embedded

藏色散人
Release: 2023-04-05 11:10:53
Original
2307 people have browsed it

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.

what is mysql embedded

## The operating environment of this tutorial: Windows 10 system, mysql8 version, Dell G3 computer.

Usage of EmbeddedMySql

What is Embedded MySql?

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.

Use of embedded MySql

First introduce the maven dependency

 com.wix wix-embedded-mysql 4.6.1 test 
Copy after login
The next step is the use of Java code. Configure parameters related to the startup of the embedded database.

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(); }}
Copy after login
You can now run the startup of embedded mysql. In this way, the database must be started every time and then the unit test is executed. We can configure startup into unit tests. Rewrite the SpringJUnit4ClassRunner class to start the embedded database at the same time.

For details, you can refer to the GitHub source code: https://github.com/wix-incubator/wix-embedded-mysql

[Related recommendations:

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!