mysql配置文件
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 100
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/www/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""
innodb_data_home_dir = /www/server/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /www/server/data
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 1
innodb_write_io_threads = 1
[mysqldump]
quick
max_allowed_packet = 500M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
创建mysql-compose.yml文件
vim mysql-compose.yml
# 文件内容
version: '3'
services:
# 创建容器
master_mysql57:
container_name: 'master_mysql57' # 容器名称
image: mysql:5.7 # 镜像名称
hostname: master_mysql57
privileged: true # 特殊权限,让容器拥有root权限
# restart后面的参数:
# no 默认策略,在容器退出时不重启容器
# on-failure 在容器非正常退出时(退出状态非0),才会重启容器
# on-failure:n 在容器非正常退出时重启容器,最多重启n次
# always docker启动,容器自动重启,在容器退出时总是重启容器
restart: always
ports:
- '3316:3306' # Sphinx默认端口
volumes:
- /www/wwwroot/:/www/wwwroot:rw
# - F:/www/wwwroot/:/www/wwwroot:rw
environment:
# environment 和 Dockerfile 中的 ENV 指令一样会把变量一直保存在镜像、容器中,类似 docker run -e 的效果。设置容器的环境变量
- container=docker
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=mysql123456
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
# 创建容器
slave_mysql57:
container_name: 'slave_mysql57' # 容器名称
image: mysql:5.7 # 镜像名称
hostname: slave_mysql57
privileged: true # 特殊权限,让容器拥有root权限
# restart后面的参数:
# no 默认策略,在容器退出时不重启容器
# on-failure 在容器非正常退出时(退出状态非0),才会重启容器
# on-failure:n 在容器非正常退出时重启容器,最多重启n次
# always docker启动,容器自动重启,在容器退出时总是重启容器
restart: always
ports:
- '3318:3306' # Sphinx默认端口
volumes:
- /www/wwwroot/:/www/wwwroot:rw
# - F:/www/wwwroot/:/www/wwwroot:rw
environment:
# environment 和 Dockerfile 中的 ENV 指令一样会把变量一直保存在镜像、容器中,类似 docker run -e 的效果。设置容器的环境变量
- container=docker
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=mysql123456
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
容器管理
# 运行容器
docker run -p 5306:3306 --name mysql57 -v /docker/mysql/var/log:/var/log/mysql -v /docker/mysql/var/data:/var/lib/mysql -v /docker/mysql/var/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=D7txumqc2b! -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
# 启动, 使用默认docker-compose.yml名称, 可以不加yml文件
docker-compose -f mysql-compose.yml up -d
# 停止
docker-compose -f mysql-compose.yml stop
# 登录mysql容器
docker exec -it master_mysql57 /bin/bash
# 登录mysql
mysql -u root -p
# 查看mysql字符集
mysql> show variables like 'character_set_%';
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 [email protected]