您好,登錄后才能下訂單哦!
由于需要修改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配置文件的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。