docker下修改mysql配置文件的方法
程序员文章站
2022-12-06 21:02:55
由于需要修改mysql的sql_mode,在命令行修改每次重启都会失效,因为修改docker下mysql的配置文件。
操作系统:centos7
docker版本:doc...
由于需要修改mysql的sql_mode,在命令行修改每次重启都会失效,因为修改docker下mysql的配置文件。
操作系统:centos7
docker版本:docker version 17.05.0-ce, build 89658be
mysql版本:5.7.18
1.拉取镜像
docker pull mysql:5.7.18
2.列出镜像
[root@zk01 ~]# docker images repository tag image id created size mysql 5.7.18 e799c7f9ae9c 5 weeks ago 407mb
3.运行docker
docker run -d -p 3306:3306 --name mymysql -e mysql_root_password=123456 mysql:5.7.18
4.列出正在运行的容器
[root@zk01 docker]# docker ps container id image command created status ports names e1066fe2db35 mysql:5.7.18 "docker-entrypoint..." 6 seconds ago up 6 seconds 0.0.0.0:3306->3306/tcp mymysql
5.进入容器
docker exec -it e1066fe2db35 /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 # by default we only accept connections from localhost #bind-address = 127.0.0.1 # disabling symbolic-links is recommended to prevent assorted security risks #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 | +-------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set
8.停止并删除容器
docker stop e1066fe2db35 docker rm e1066fe2db35
9.重新启动容器,指定数据目录和配置文件
docker run -d -p 3306:3306 -v /soft/mysql/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /soft/mysql/data:/var/lib/mysql -e mysql_root_password=123456 --name mymysql mysql:5.7.18
10.查看sql_mode
mysql> select @@global.sql_mode; +-------------------+ | @@global.sql_mode | +-------------------+ | | +-------------------+ 1 row in set mysql> select @@session.sql_mode; +--------------------+ | @@session.sql_mode | +--------------------+ | | +--------------------+ 1 row in set
总结
以上所述是小编给大家介绍的docker下修改mysql配置文件的方法,希望对大家有所帮助
下一篇: 被打感觉不错