由于需要修改mysql的sql_mode,在命令行修改每次重啟都會失效,因為修改docker下mysql的配置文件。
操作系統(tǒng):centos7
docker版本:Docker version 17.05.0-ce, build 89658be
mysql版本:5.7.18
1.拉取鏡像
2.列出鏡像
[root@zk01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7.18 e799c7f9ae9c 5 weeks ago 407MB
3.運(yùn)行docker
docker run -d -p 3306:3306 --name mymysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.18
4.列出正在運(yùn)行的容器
[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.進(jìn)入容器
docker exec -it e1066fe2db35 /bin/bash
6.查看配置文件
/etc/mysql/mysql.conf.d/mysqld.cnf
配置文件內(nèi)容:
[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.重新啟動容器,指定數(shù)據(jù)目錄和配置文件
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
總結(jié)
以上所述是小編給大家介紹的docker下修改mysql配置文件的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!