docker下修改mysql配置文件的方法
由于需要修改mysql的sql_mode,在命令行修改每次重启都会失效,因为修改docker下mysql的配置文件。
操作系统:centos7
docker版本:Dockerversion17.05.0-ce,build89658be
mysql版本:5.7.18
1.拉取镜像
dockerpullmysql:5.7.18
2.列出镜像
[root@zk01~]#dockerimages REPOSITORYTAGIMAGEIDCREATEDSIZE mysql5.7.18e799c7f9ae9c5weeksago407MB
3.运行docker
dockerrun-d-p3306:3306--namemymysql-eMYSQL_ROOT_PASSWORD=123456mysql:5.7.18
4.列出正在运行的容器
[root@zk01docker]#dockerps CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e1066fe2db35mysql:5.7.18"docker-entrypoint..."6secondsagoUp6seconds0.0.0.0:3306->3306/tcpmymysql
5.进入容器
dockerexec-ite1066fe2db35/bin/bash
6.查看配置文件
/etc/mysql/mysql.conf.d/mysqld.cnf
配置文件内容:
[mysqld] pid-file=/var/run/mysqld/mysqld.pid socket=/var/run/mysqld/mysqld.sock datadir=/var/lib/mysql #log-error=/var/log/mysql/error.log #Bydefaultweonlyacceptconnectionsfromlocalhost #bind-address=127.0.0.1 #Disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks #symbolic-links=0
7.查看mysql的sql_mode
mysql>SELECT@@GLOBAL.sql_mode; +-------------------------------------------------------------------------------------------------------------------------------------------+ |@@GLOBAL.sql_mode| +-------------------------------------------------------------------------------------------------------------------------------------------+ |ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION| +-------------------------------------------------------------------------------------------------------------------------------------------+ 1rowinset
8.停止并删除容器
dockerstope1066fe2db35 dockerrme1066fe2db35
9.重新启动容器,指定数据目录和配置文件
dockerrun-d-p3306:3306-v/soft/mysql/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf-v/soft/mysql/data:/var/lib/mysql-eMYSQL_ROOT_PASSWORD=123456--namemymysqlmysql:5.7.18
10.查看sql_mode
mysql>SELECT@@GLOBAL.sql_mode; +-------------------+ |@@GLOBAL.sql_mode| +-------------------+ || +-------------------+ 1rowinset mysql>SELECT@@SESSION.sql_mode; +--------------------+ |@@SESSION.sql_mode| +--------------------+ || +--------------------+ 1rowinset
总结
以上所述是小编给大家介绍的docker下修改mysql配置文件的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!