mysql安装(5.7)
docker run -p 3306:3306 --name mysql -v /app/mysql/log:/var/log/mysql -v /app/mysql/data:/var/lib/mysql -v /app/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
mysql8安装
#8.x版本,引入了 secure-file-priv 机制,磁盘挂载将没有权限读写data数据,所以需要将权限透传, 或者chmod -R 777 /app/mysql/data # --privileged 特权容器,容器内使用真正的root用户 docker run -p 3306:3306 --name mysql8 -v /app/mysql/conf:/etc/mysql/conf.d -v /app/mysql/log:/var/log/mysql -v /app/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --privileged -d mysql
修改mysql5.7的配置文件
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf /root/mysqld.cnf • 1
配置文件
# Copyright (c) 2014, 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 # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [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 character_set_server=utf8 init_connect='SET NAMES utf8' max_allowed_packet = 20M [mysql] default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 [client] default-character-set = utf8
将修改后的配置放到容器
docker cp /root/mysqld.cnf mymysql:/etc/mysql/mysql.conf.d/