***主从备份之后,从数据库不能写,只能读操作,不然数据会错乱
一、在两台Linux机器上安装MySQL(参考"centos7+mysql5.7")
二、Master主服务器配置(192.168.56.102)
log_bin_index = master-bin.index
备注:server-id 服务器唯一标识,log_bin 启动MySQL二进制日志,binlog_do_db 指定记录二进制日志的数据库,binlog_ignore_db 指定不记录二进制日志的数据库。
grant replication slave on *.* to 'masterbackup' @'192.168.56.%' identified by '123456';
(192.168.1.%通配符,表示0-255的IP都可访问主服务器,正式环境请配置指定从服务器IP)
relay-log-index = slave-relay-bin.index
change master to master_host='192.168.56.102',master_port=3306,master_user='masterbackup',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;
备注:master_host对应主服务器的IP地址,master_port对应主服务器的端口,master_log_file对应show master status显示的File列:master-bin.000001,master_log_pos对应Position列:154,否则有可能出现同步失败。
备注:Slave_IO_Running和Slave_SQL_Running都为yes才表示同步成功。
1、Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work
删除(删除之后 要重启mysql): /var/lib/mysql/auto.cnf 文件
change master to master_host='192.168.56.102',master_port=3306,master_user='masterbackup',master_password='123456',master_log_file='master-bin.000011',master_log_pos=76010;