sudo docker run --name mysql5.7 -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456 -d mysql:5.7
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c84a366e3abf mysql:5.7 "docker-entrypoint..." 4 minutes ago Up 15 seconds 33060/tcp, 0.0.0.0:4306->3306/tcp mysql5.7
[root@localhost ~]# docker exec -it mysql5.7 /bin/bash root@c84a366e3abf:/# cat /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/ root@c84a366e3abf:/# cat /etc/mysql/mysql.conf.d/mysqld.cnf # 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 lower_case_table_names=1 #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
[root@localhost ~]# docker stop mysql5.7 [root@localhost ~]# docker rm mysql5.7
[root@localhost ~]# cd /opt [root@localhost ~]# mkdir mysql [root@localhost ~]# cd mysql [root@localhost ~]# mkdir data [root@localhost ~]# mkdir config [root@localhost ~]# cd config [root@localhost ~]# touch mysqld.cnf
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql lower_case_table_names=1 #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
sudo docker run --name mysql5.7 --restart always --privileged=true -p 4306:3306 -v /opt/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /opt/mysql/data:/var/lib/mysql -e MYSQL_USER="fengwei" -e MYSQL_PASSWORD="pwd123" -e MYSQL_ROOT_PASSWORD="rootpwd123" -d mysql:5.7
–restart always:开机启动 –privileged=true:提升容器内权限 -v /opt/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf:映射配置文件 -v /opt/mysql/data:/var/lib/mysql:映射数据目录 -e MYSQL_USER=”fengwei”:添加用户fengwei -e MYSQL_PASSWORD=”pwd123”:设置fengwei的密码伟pwd123 -e MYSQL_ROOT_PASSWORD=”rootpwd123”:设置root的密码伟rootpwd123
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Docker安装MySql-挂载外部数据和配置 - Python技术站