一、master 服务器配置
1、master 服务器my.cnf配置
server_id=1
log-bin=mysql-bin
2、master 重启并查看master 状态
show master status;
结果; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 2043 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
3、master 开启远程访问权限
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option;
4、master 关闭防火墙
systemctl stop firewalld.service
二、slave 服务器配置
1、slave 服务器my.cnf 配置
server_id=2 log-bin=mysql-bin binlog_do_db=test
2、slave 服务器重启并配置指向master
change master to master_host=‘192.168.1.7‘,master_user=‘root‘,master_password=‘123456‘, master_log_file=‘mysql-bin.000001‘,master_log_pos=154;
3、slave 开启同步
start slave
4、查看slave 状态
show slave status \G; 结果: Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.7 Master_User: root Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 2043 Relay_Log_File: msyqlslave-relay-bin.000004 Relay_Log_Pos: 576 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes