docker mysql主从

2020-07-15  本文已影响0人  Marksirl
docker 运行配置
docker run --name mysql-master -p 41550:3306 -v /Users/zrone/datum/docker/mysql/master:/usr/local/mysql -v /Users/zrone/datum/docker/mysql/conf/master:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 -d 5d9483f9a7b2
docker run --name mysql-slave01 -p 41551:3306 -v /Users/zrone/datum/docker/mysql/slave01:/usr/local/mysql -v /Users/zrone/datum/docker/mysql/conf/slave01:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 -d 5d9483f9a7b2
附docker mysql 配置文件
socket = /tmp/mysqld.sock

[mysqld]
# Only allow connections from localhost
bind-address = 0.0.0.0
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8mb4
default-time-zone = '+8:00'
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysqld.pid

# 慢查询
slow_query_log = 1
long_query_time = 10
slow_query_log_file = /usr/local/mysql/log/mysql-slow.log

# log-bin
log_bin = /usr/local/mysql/log/mysql-bin.log
# 日志过期时间,设置为0则永不过期
expire_logs_days = 0
# 1. STATEMENT模式 2. ROW 3. MIXED
binlog_format = ROW
max_binlog_size = 100M
binlog_cache_size = 4M
max_binlog_cache_size = 256M
# 1表示表示每次事务提交,MySQL都会把binlog刷下去,设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多,通常设置为100或者是0。这样牺牲一定的一致性,可以获得更高的并发和性能。
sync_binlog = 1
# 不同步哪些数据库
binlog_ignore_db = mysql
binlog_ignore_db = test
binlog_ignore_db = information_schema
# 只同步哪些数据库,除此之外,其他不同步
# binlog_do_db = demo

# 0: log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行。该模式下在事务提交的时候,不会主动触发写入磁盘的操作
# 1: 每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去,该模式为系统默认。
# 2: 每次事务提交时MySQL都会把log buffer的数据写入log file,但是flush(刷到磁盘)操作并不会同时进行。该模式下,MySQL会每秒执行一次 flush(刷到磁盘)操作。
innodb_flush_log_at_trx_commit = 2

server-id = 1
# 当slave从库宕机后,假如relay-log损坏了,导致一部分中继日志没有处理,则自动放弃所有未执行的relay-log,并且重新从master上获取日志,这样就保证了relay-log的完整性。
relay_log_recovery = 1
# 当slave从主数据库读取log数据失败后,等待多久重新建立连接并获取数据,默认3600秒
slave_net_timeout = 5

# 
lc-messages-dir = /usr/local/mysql/share/english/
lc-messages = en_US

sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
GRANT ALL PRIVILEGES ON *.* TO 'sync'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
CREATE USER 'sync'@'*' IDENTIFIED BY '123456';
show master status;
CHANGE MASTER TO \
MASTER_HOST='172.17.0.2', \
MASTER_USER='sync', \
MASTER_PORT=3306, \
MASTER_PASSWORD='123456', \
MASTER_LOG_FILE='mysql-bin.000003', \
MASTER_LOG_POS=841;
start slave;
show slave status\G;
上一篇下一篇

猜你喜欢

热点阅读