主实例配置:
[mysqld]
log-bin=mysql-bin #/ [必须]启用二进制日志
server-id=1 # [必须]服务器唯一ID
从实例配置:
[mysqld]
log-bin=mysql-bin # [非必须]Slave可以不启用二进制日志,配置二进制日志可以便于Master和Slave交换角色
server-id=2 # [必须]服务器唯一ID
在Master上使用root用户登录建立同步账户并授权Slave
mysql> GRANT REPLICATION SLAVE ON *.* to ‘lover‘@‘%‘ identified by ‘kiss‘;
mysql> FLUSH PRIVILEGES;
使用root账户登录Master查看Master状态
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 6584 | thisonedb | mysql | |
+------------------+----------+--------------+------------------+-------------------+
配置Slave跟踪Master日志的位置
mysql> change master to master_host=‘127.0.0.1‘,master_user=‘lover‘,master_password=‘kiss‘,master_log_file=‘mysql-bin.000002‘,master_log_pos=6584 ;
mysql> start slave;
使用root账户登录MySQL核对Slave状态,看到如下信息就说明配置成功了
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.16.13.128
Master_User: username
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 6584
Relay_Log_File: bx-13-129-relay-bin.000003
Relay_Log_Pos: 6797
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes