環(huán)境說明
OS:centos 7
MySQL:5.7.38
主:10.4.7.41
備:10.4.7.42
基礎(chǔ)環(huán)境處理
略
Mysql安裝
略
Mysql主從配置
Master配置
lower_case_table_names=1
character-set-server=utf8
max_connections=1024
server-id=104741 ###主從id一定要配置不同
log-bin=mysql-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
expire_logs_days=7
Slave配置
lower_case_table_names=1
character-set-server=utf8
max_connections=1024
server-id=104742 ###主從id一定要配置不同
# log-bin=mysql-bin
# binlog-ignore-db=information_schema
# binlog-ignore-db=performance_schema
# binlog-ignore-db=mysql
# replicate-ignore-db=mysql.%
log-slave-updates
slave-skip-errors=all
slave.NET-timeout=60
expire_logs_days=7
配置說明:
binlog-ignore-db:忽略某個庫binlog日志記錄,一般在主庫上配置
binlog-do-db:記錄某個庫binlog日志記錄,一般在主庫上配置
replicate-ignore-db:用來設(shè)置不需要同步的庫,一般在從庫上配置
replicate-do-db:用來設(shè)置需要同步的庫,一般在從庫上配置
創(chuàng)建數(shù)據(jù)同步用戶
grant replication slave,reload,super on *.* to sync_slave@'%' identified by 'Aa123456?';
flush privileges;
show master status;
查看master狀態(tài)
創(chuàng)建數(shù)據(jù)同步配置
change master to master_host='10.4.7.41',master_user='sync_slave',master_password='Aa123456?',master_log_file='mysql-bin.000002',master_log_pos=154;
查看主從同步狀態(tài)
show slave status G;
只有看到下圖中兩個Running的狀態(tài)都是Yes的時候才說明主從同步正常。
主從同步狀態(tài)