Create a new file: /my/mysql/my.cnf
Copy the following contents (or start a docker mysql and copy the contents of /etc/mysql.cnf)
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ! includedir /etc/mysql/conf.d/ ! includedir /etc/mysql/mysql.conf.d/ [mysqld] sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' lower_case_table_names=0Copy the code
Run the following command
Docker run - ring = true - name mysql5.7 -p 3306:3306 - v/my/mysql/datadir: / var/lib/mysql - v /my/mysql/conf.d:/etc/mysql/conf.d -v /my/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=yourpassword -d Mysql: 5.7Copy the code
The following two lines are configured to mount data
-v /my/mysql/datadir:/var/lib/mysql
-v /my/mysql/conf.d:/etc/mysql/conf.d
Copy the code
Mount the mysql configuration file – v/my/mysql/my CNF: / etc/mysql/my CNF
After startup, modify /my/mysql/my.cnf and restart the mysql container corresponding to docker to take effect
Docker ps # find the corresponding container ID # restart container
docker stop 3
docker start 3
Copy the code