一、master 服务器配置
1、master 服务器my.cnf配置
server_id=1log-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;
FLUSH PRIVILEGES
4、master 关闭防火墙
systemctl stop firewalld.service
二、slave 服务器配置
1、slave 服务器my.cnf 配置
server_id=2log-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: Waitingformaster to send event
Master_Host:192.168.1.7Master_User: root
Master_Port:3306Connect_Retry:60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos:2043Relay_Log_File: msyqlslave-relay-bin.000004Relay_Log_Pos:576Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: Yes
Slave_SQL_Running: Yes