MySQL主从复制踩坑

1.在主库上创建一个用来复制的用户,要配置好可以登录的ip,我这里选无限制
grant all privileges on *.* to 'user'@'%' identified by 'password' with grant option;

2.把相应的库转储为SQL在从库上创建,可以用可视化工具做

3.给从库在/etc/my.cnf下添加server-id=2区分主库

4.在从库cd /var/lib/mysql mv auto.cnf auto.cnf.bak,因为从库是从主库拷贝而来的,所以server UUID与主库一样,要删除该文件

5.systemctl restart mysqld重启MySQL服务,使配置生效

6.mysql -uroot -p登录mysql

7.配置复制链路change master to master_host='49.234.206.154',master_user='im_',master_password='123456' -> ,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=154;
MASTER_LOG_FILE 和MASTER_LOG_POS从主库转储的SQL可以查看,若是报该错误则是因为server-id没配
ERROR 1794 (HY000): Slave is not configured or failed to initialize properly. You must at least set --server-id to enable either a master or a slave. Additional error messages can be found in the MySQL error log

8.配置过滤链路
change replication filter replicate_rewrite_db=((imooc_db,product_db));
若报如下错误则可能是因为没有配置过滤链路导致从库中找不到相应的表
Error executing row event: 'Table 'ss_db.customer_level_inf' doesn't exist'

9.开启slavestart slave 查看slave链路show slave status \G

image.png

slave_IO_Running和slave_SQL_Running为YES则成功

10.测试

从库
image.png

修改主库
image.png

从库
image.png

你可能感兴趣的:(MySQL主从复制踩坑)