docker-compose部署MySQL5.7
不说废话直接上
- 编辑mysql配置
$ vim my.cnf
# 这个配置要挂载进去
[client]
port = 3306
socket = /var/lib/mysql/data/mysql.sock
[mysqld]
# 针对5.7版本执行group by字句出错问题解决
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
# 一般配置选项
basedir = /var/lib/mysql
datadir = /var/lib/mysql/data
port = 3306
socket = /var/lib/mysql/data/mysql.sock
lc-messages-dir = /usr/share/mysql # 务必配置此项,否则执行sql出错时,只能显示错误代码而不显示具体错误消息
character-set-server=utf8mb4
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 64M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
#tx_isolation = READ-COMMITTED
tmp_table_size = 64M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1024M
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
wait_timeout= 31536000
interactive_timeout= 31536000
lower_case_table_names = 1
- 编辑docker-compose.yml
$ vim docker-compose.yml
# mysql数据要挂载出来,注意自行修改配置目录
version: '3'
services:
mysql:
hostname: mysql
image: mysql:5.7.26
# network_mode: "host" # 如果需要容器使用宿主机IP(内网IP),则可以配置此项
container_name: mysql # 指定容器名称,如果不设置此参数,则由系统自动生成
restart: unless-stopped # 设置容器自启模式
command: mysqld
environment:
- TZ=Asia/Shanghai # 设置容器时区与宿主机保持一致
- MYSQL_ROOT_PASSWORD=root # 设置root密码
volumes:
# 数据挂载目录自行修改哦!
- /etc/localtime:/etc/localtime:ro # 设置容器时区与宿主机保持一致
- /data/mysql/data:/var/lib/mysql/data # 映射数据库保存目录到宿主机,防止数据丢失
- /data/mysql/my.cnf:/etc/mysql/my.cnf # 映射数据库配置文件
- 启动MySQL5.7
$ docker-compose up -d
- 使用
mysql -uroot -p -h 127.0.0.1
# 输入设置的密码即可
# 默认已给root用户授权,其它用户自行创建并授权
版权声明:本文为ykd_202020原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。