mysql5.7.22双机热备份(个人笔记)

1.配置my.cnf文件

修改A的/etc/my.cnf 文件,在my.cnf 配置项中加入下面配置:

server-id = 1      #Server 标识
log-bin
binlog-do-db=test  #指定需要日志的数据库

2.分别进入mysql

主机A:106.14.200.10

CHANGE MASTER TO
MASTER_HOST='106.14.200.12',
MASTER_USER='root',
MASTER_PASSWORD='root账户密码',
MASTER_PORT=3306,
MASTER_LOG_FILE='master_02.000007',//在主机B中mysql中执行show master status\G;可获取该值
MASTER_LOG_POS=1284,//在主机B中mysql中执行show master status\G;可获取该值
MASTER_CONNECT_RETRY=101;//service-id

主机B:106.14.200.12

CHANGE MASTER TO
MASTER_HOST='106.14.200.10',
MASTER_USER='root',
MASTER_PASSWORD='root账户密码',
MASTER_PORT=3306,
MASTER_LOG_FILE='master_01.000006',//在主机A中mysql中执行show master status\G;可获取该值
MASTER_LOG_POS=154,//在主机A中mysql中执行show master status\G;可获取该值
MASTER_CONNECT_RETRY=106;//service-id

防止同步时出如下错误:

Column 2 of table 'test.t_audio' cannot be converted from type 'varchar(765(bytes))' to type 'varcha

需要分别给对应的db中的表都加上

Alter table tablea convert to character set utf8;
Alter table tableb convert to character set utf8;
......

分别开启slave

start slave;

分别查看slave状态:

mysql> show slave status\G;
屏幕快照 2020-03-22 22.48.09.png

你可能感兴趣的:(mysql5.7.22双机热备份(个人笔记))