docker持久化部署mysql

启动mysql ,挂载配置文件,数据持久化到宿主主机

mkdir -p /data/mysql/conf
mkdir -p /data/mysql/data
mkdir -p /data/mysql/log
在mysql目录中创建my.cnf文件,把下面的复制到文件里面保存一下
vim /data/mysql/my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Custom config should go here
!includedir /etc/mysql/conf.d/
[mysqld]
user=mysql
#服务端口号 默认3306
port=3306
#忽略表名大小写
lower_case_table_names=1
character-set-server=utf8
#密码加密
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
#mysql8会有group by 报错这样可以避免
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

docker启动mysql8

docker run \
-p 3317:3306 \
--name zhdj-3317 \
--restart=always \
-v /data/mysql/log:/var/log/mysql \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/my.cnf:/etc/mysql/my.cnf \
-v /data/mysql/conf/conf.d:/etc/mysql/conf.d \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=123qweQWE \
-d docker.funi.local:5000/mysql:8.0.35  --lower_case_table_names=1

docker启动mysql7

docker run \
-p 3306:3306 \
--name nacos_mysql \
--restart=always \
-v /data/mysql/log:/var/log/mysql \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/my.cnf:/etc/mysql/my.cnf \
-v /data/mysql/conf/conf.d:/etc/mysql/conf.d \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=123qweQWE \
-d docker.funi.local:5000/mysql:5.7  --lower_case_table_names=1
posted @ 2024-04-08 11:33  村尚chun叔  阅读(102)  评论(0编辑  收藏  举报