确认my.cnf中有如下参数:
binlog_format=row gtid_mode = on enforce_gtid_consistency = on log-slave-updates = 1 skip_slave_start = 1
grant replication slave on *.* to rep@'192.168.56.%' identified by 'pwd4rep'; flush privileges;
change master to master_host='192.168.56.3', master_port=3306, master_user='rep', master_password='pwd4rep', master_auto_position=1; start slave; show slave status \G
mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.3 Master_User: rep Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 39031 Relay_Log_File: mysql34-relay-bin.000002 Relay_Log_Pos: 551 Relay_Master_Log_File: mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1032 Last_Error: Could not execute Delete_rows event on table mysql.user; Can't find record in 'user', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000003, end_log_pos 1032 Skip_Counter: 0 Exec_Master_Log_Pos: 341 Relay_Log_Space: 39447 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 1032 Last_SQL_Error: Could not execute Delete_rows event on table mysql.user; Can't find record in 'user', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000003, end_log_pos 1032 Replicate_Ignore_Server_Ids: Master_Server_Id: 23306 Master_UUID: c4ae4721-db75-11e4-9f41-08002796172a Master_Info_File: /data/mysql/user_3306/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: 150413 07:43:00 Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: c4ae4721-db75-11e4-9f41-08002796172a:1-161 Executed_Gtid_Set: 9a7aa8fd-e1d1-11e4-88b8-080027500de9:1, c4ae4721-db75-11e4-9f41-08002796172a:1 Auto_Position: 1 1 row in set (0.00 sec)
</pre><pre name="code" class="sql">stop slave; set session gtid_next='c4ae4721-db75-11e4-9f41-08002796172a:2'; begin; commit; set session gtid_next=automatic; start slave;
mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.3 Master_User: rep Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 39031 Relay_Log_File: mysql34-relay-bin.000003 Relay_Log_Pos: 691 Relay_Master_Log_File: mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 39031 Relay_Log_Space: 39987 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 23306 Master_UUID: c4ae4721-db75-11e4-9f41-08002796172a Master_Info_File: /data/mysql/user_3306/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: c4ae4721-db75-11e4-9f41-08002796172a:1-161 Executed_Gtid_Set: 9a7aa8fd-e1d1-11e4-88b8-080027500de9:1, c4ae4721-db75-11e4-9f41-08002796172a:1-161 Auto_Position: 1 1 row in set (0.00 sec)
mysql> select user,host from mysql.user; +------+--------------+ | user | host | +------+--------------+ | root | 127.0.0.1 | | rep | 192.168.56.% | | root | ::1 | | | localhost | | root | localhost | | | mysql34 | | root | mysql34 | +------+--------------+ 7 rows in set (0.00 sec)
mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | dept | | emp | | t1 | | t10 | | t100 | | test | +----------------+ 6 rows in set (0.01 sec)