沉默的背影 X-Pacific

keep learning

docker创建mysql容器,并挂载数据+配置

新建:/my/mysql/my.cnf (准备挂载配置文件用)

将以下内容拷贝进去(或者启动一个docker的mysql,并且把/etc/mysql/my.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=0

运行如下命令

docker run --privileged=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.7

下面这两行配置是挂载数据

-v /my/mysql/datadir:/var/lib/mysql
-v /my/mysql/conf.d:/etc/mysql/conf.d

挂载mysql配置文件
-v /my/mysql/my.cnf:/etc/mysql/my.cnf

启动后修改/my/mysql/my.cnf并重启docker对应mysql容器即可生效配置

docker ps #找到对应容器ID
#重启容器
docker stop 3
docker start 3

 

posted @ 2019-08-21 17:17  乂墨EMO  阅读(8173)  评论(1编辑  收藏  举报