侧边栏壁纸
  • 累计撰写 30 篇文章
  • 累计创建 35 个标签
  • 累计收到 4 条评论

docker 部署mysql

GoDan
2022-06-21 / 0 评论 / 0 点赞 / 108 阅读 / 1,731 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-06-22,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

搜索可用镜像

https://hub.docker.com/_/mysql?tab=tags&page=1&name=5.7
image

下载镜像

[root@01 ~]# docker pull mysql:5.7.36
5.7.36: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7.36
docker.io/library/mysql:5.7.36

[root@01 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
mysql        5.7.36    c20987f18b13   6 months ago   448MB

运行镜像

# 创建配置文件
cat > /data/db/mysql/my.cnf << EOF
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql

symbolic-links=0
skip-host-cache
skip-name-resolve
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
group_concat_max_len=102400

server-id = 1
lower_case_table_names = 1

log_bin = mysql-bin
sync_binlog = 1
expire_logs_days =7
binlog_format = ROW

innodb_buffer_pool_size = 4G
innodb_log_file_size = 256
max_connections = 500
wait_timeout = 3600
interactive_timeout = 3600
skip_name_resolve = 1
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysql]

[mysqldump]
quick
quote-names
max_allowed_packet = 16M
EOF
# 启动运行
docker run -itd -p 3366:3306 --name mysql -v /data/db/mysql/my.cnf:/etc/mysql/my.cnf -v /data/logs/mysql:/var/log/mysql -v /data/db/mysql/data:/var/lib/mysql -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.36

参数说明

  • -p 3366:3306   将容器的 3366 端口映射到主机的 3306 端口

  • –name mysql 启动后容器名为 mysql

  • -v /data/db/mysql/data:/var/lib/mysql     将主机目录挂载到容器的目录

  • -e MYSQL_ROOT_PASSWORD=123456   初始化 root 用户的密码

0

评论区