MySql教程

Docker 安装 MySQL5.7

本文主要是介绍Docker 安装 MySQL5.7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

转自:https://www.cnblogs.com/418836844qqcom/p/11692237.html

 

1.安装mysql5.7 docker镜像:

docker pull mysql:5.7

2.查看镜像库:

docker images

3. 在本地创建mysql的映射目录 

mkdir -p /root/mysql/data  /root/mysql/conf  /root/mysql/logs

 4.在/root/mysql/conf中创建  mysqld.cnf文件,并添加配置文件内容

cd   /root/mysql/conf
vi   mysqld.cnf
复制代码
[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8
 
[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
lower_case_table_names=1
 
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
 
max_connections = 1000
复制代码

 

5.创建容器,将数据,日志,配置文件映射到本机

 

docker run --name mysql -p 3306:3306 --restart=always -e MYSQL_ROOT_PASSWORD=root  -v /root/mysql/conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /root/mysql/data:/var/lib/mysql   -v /root/mysql/log:/var/log/mysql  -d  mysql:5.7 

这篇关于Docker 安装 MySQL5.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!