mysql1部署
[root@harbor mysql_cluster]# tree
├── conf
│ └── my.cnf
├── mysqldb
└── mysql.yaml
mysql.yaml
version: '3'
services:
mysql:
image: mysql:5.7.37
restart: always
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: root
TZ: Asia/Shanghai
ports:
- 3306:3306
volumes:
- ./mysqldb:/var/lib/mysql
- ./config/my.cnf:/etc/mysql/my.cnf
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--default-authentication-plugin=mysql_native_password
my.cnf
[mysqld]
log-bin
skip-host-cache
skip-name-resolve
default-time-zone = '+8:00'
sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
lower_case_table_names=1
skip-host-cache
skip-name-resolve
user=mysql
symbolic-links=0
server-id=1
autocommit=1
collation-server=utf8mb4_unicode_ci
character_set_server=utf8mb4
skip_name_resolve=1
max_connections=8000
max_connect_errors=1000
join_buffer_size=128M
tmp_table_size=64M
max_allowed_packet=64M
interactive_timeout=1200
wait_timeout=600
read_buffer_size=16M
read_rnd_buffer_size=8M
sort_buffer_size=8M
binlog_format=row
max_binlog_size=1G
sync_binlog=5
slow_query_log=1
long_query_time=6
log_queries_not_using_indexes=1
log_slow_admin_statements=1
log_throttle_queries_not_using_indexes=10
expire_logs_days=90
min_examined_row_limit=100
innodb_buffer_pool_size=2G
innodb_buffer_pool_instances=8
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_lock_wait_timeout=30
启动服务
docker-compose -f mysql.yaml up -d
mysql2部署
[root@harbor mysql_cluster]# tree
├── conf
│ └── my.cnf
├── mysqldb
└── mysql.yaml
mysql.yaml
version: '3'
services:
mysql1:
image: mysql:5.7.37
restart: always
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: root
TZ: Asia/Shanghai
ports:
- 3307:3306
volumes:
- ./mysqldb:/var/lib/mysql
- ./config/my.cnf:/etc/mysql/my.cnf
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--default-authentication-plugin=mysql_native_password
my.cnf
[mysqld]
log-bin
skip-host-cache
skip-name-resolve
default-time-zone = '+8:00'
sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
lower_case_table_names=1
skip-host-cache
skip-name-resolve
user=mysql
symbolic-links=0
server-id=1
autocommit=1
collation-server=utf8mb4_unicode_ci
character_set_server=utf8mb4
skip_name_resolve=1
max_connections=8000
max_connect_errors=1000
join_buffer_size=128M
tmp_table_size=64M
max_allowed_packet=64M
interactive_timeout=1200
wait_timeout=600
read_buffer_size=16M
read_rnd_buffer_size=8M
sort_buffer_size=8M
binlog_format=row
max_binlog_size=1G
sync_binlog=5
slow_query_log=1
long_query_time=6
log_queries_not_using_indexes=1
log_slow_admin_statements=1
log_throttle_queries_not_using_indexes=10
expire_logs_days=90
min_examined_row_limit=100
innodb_buffer_pool_size=2G
innodb_buffer_pool_instances=8
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_lock_wait_timeout=30
启动服务
docker-compose -f mysql.yaml up -d
注意
主要解决的问题:mysql在同一台机器上部署的时候需要设置不同的id,否则会出现重新创建现象。
**即my.cnf里面的“server-id”需要不一样**