免安装原生产环境的MySQL是什么
发表于:2025-11-10 作者:千家信息网编辑
千家信息网最后更新 2025年11月10日,这篇文章主要介绍"免安装原生产环境的MySQL是什么",在日常操作中,相信很多人在免安装原生产环境的MySQL是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"免安装
千家信息网最后更新 2025年11月10日免安装原生产环境的MySQL是什么
这篇文章主要介绍"免安装原生产环境的MySQL是什么",在日常操作中,相信很多人在免安装原生产环境的MySQL是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"免安装原生产环境的MySQL是什么"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
就是它:
com.wix wix-embedded-mysql x.y.z test
代码也简单,直接定义你需要的版本,数据库信息,把要初始化的SQL 给它,走起。
MysqldConfig config = aMysqldConfig(v5_6_23) //这里是版本 .withCharset(UTF8) .withPort(2215) .withUser("user1", "pwd2") .withTimeZone("Europe/Vilnius") .withTimeout(2, TimeUnit.MINUTES) .withServerVariable("max_connect_errors", 666) .build(); EmbeddedMysql mysqld = anEmbeddedMysql(config) .addSchema("aschema", ScriptResolver.classPathScript("db/001_init.sql")) .start(); //do work mysqld.stop(); //optional, as there is a shutdown hook这有啥优势:
测试可以跑在和生产环境基本一致的环境,同样的版本,同样的编码和配置,database/schema/user settings 等等
比安装一个更容易,想切换版本,改配置也更轻松;
本地每个项目可以使用不同的版本,不同的配置,啥都不用担心;
对于MySQL的多个版本支持 - 5.5, 5.6, 5.7, 8.0;
多种平台和环境都支持。
原理
这背后是怎么实现的呢?
咱们是「刨根究底」公众号,一起来看看。
上面代码配置之后的 start ,到底 start 了啥?
咱们看下面这几小段代码:
protected EmbeddedMysql( final MysqldConfig mysqldConfig, final DownloadConfig downloadConfig) { this.config = mysqldConfig; IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(mysqldConfig, downloadConfig).build(); MysqldStarter mysqldStarter = new MysqldStarter(runtimeConfig); localRepository.lock(); try { this.executable = mysqldStarter.prepare(mysqldConfig); } finally { localRepository.unlock(); } try { executable.start(); getClient(SCHEMA, mysqldConfig.getCharset()).executeCommands( format("CREATE USER '%s'@'%%' IDENTIFIED BY '%s';", mysqldConfig.getUsername(), mysqldConfig.getPassword())); } catch (IOException e) { throw new RuntimeException(e); } }protected MysqldProcess start( final Distribution distribution, final MysqldConfig config, final IRuntimeConfig runtime) throws IOException { logger.info("Preparing mysqld for startup"); Setup.apply(config, executable, runtime); logger.info("Starting MysqldProcess"); return new MysqldProcess(distribution, config, runtime, this); }其实这背后依赖了一个叫embed.process的开源项目,
public AbstractProcess(Distribution distribution, T config, IRuntimeConfig runtimeConfig, E executable) throws IOException { this.config = config; this.runtimeConfig = runtimeConfig; this.executable = executable; this.distribution = distribution; // pid file needs to be set before ProcessBuilder is called this.pidFile = pidFile(this.executable.getFile().executable()); ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); // Refactor me - to much things done in this try/catch String nextCall=""; try { nextCall="onBeforeProcess()"; onBeforeProcess(runtimeConfig); nextCall="newProcessBuilder()"; ProcessBuilder processBuilder = ProcessControl.newProcessBuilder( runtimeConfig.getCommandLinePostProcessor().process(distribution, getCommandLine(distribution, config, this.executable.getFile())), getEnvironment(distribution, config, this.executable.getFile()), true); nextCall="onBeforeProcessStart()"; onBeforeProcessStart(processBuilder, config, runtimeConfig); nextCall="start()"; process = ProcessControl.start(config.supportConfig(), processBuilder); nextCall="writePidFile()"; if (process.getPid() != null) { writePidFile(pidFile, process.getPid()); } nextCall="addShutdownHook()"; if (runtimeConfig.isDaemonProcess() && !executable.isRegisteredJobKiller()) { ProcessControl.addShutdownHook(new JobKiller()); registeredJobKiller = true; } nextCall="onAfterProcessStart()"; onAfterProcessStart(process, runtimeConfig); } catch (IOException iox) { stop(); throw iox; } }它又操作了什么呢?从名字你也猜到了,它是直接操作进程的,实际在运行时,会下载一个MySQL,然后通过脚本启停。
初次启动的时候,会直接下载
有了这些,在测试的时候就可以和生产环境一样,启动时加载初始化SQL脚本,开始你的工作了。
github地址:https://github.com/wix/wix-embedded-mysql
到此,关于"免安装原生产环境的MySQL是什么"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
环境
生产
版本
学习
配置
代码
不同
时候
更多
背后
脚本
项目
帮助
支持
测试
实用
一致
刨根究底
接下来
不用
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
mac搭建本地sip服务器
企业服务器选购
网络安全等级保护备案要多久
数据库mysql如何添加列
快递数据库管理
互联网粉丝节科技
中国2017年网络安全政策
服务器主机用什么系统
网络安全有考证吗
办公室网络安全应急预案演练
网络安全普法禁毒教育考试题
云集网络技术香港有限公司
发票管理数据库
建站服务器单核双核怎么选
湖北电商网络安全维护管理系统
数据库查询没有挂科的学生姓名
四川专业汽配软件开发价格
郑州商裕软件开发有限公司
服务器网络维护技术
老年人搜索软件开发
微擎 模块对应数据库
陕西红色文化馆软件开发系统
华为服务器管理口ip
家用电脑和网站服务器的区别
软件开发岗位分析范文
数据库对会计
牛为网络技术有限公司郑州
客户端 云服务器
豪尔互联网科技有限公司
黑色沙漠服务器选不了