主服务器崩溃后,我无法同步从服务器。 你能否告诉我是否可以恢复(没有数据/交易丢失)还是必须创build一个新的从服务器?
请注意,我在这个错误之后弯腰奴隶:
mysql> SHOW SLAVE STATUS \G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.1.1 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000010 Read_Master_Log_Pos: 940132528 Relay_Log_File: cb1s-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000010 Slave_IO_Running: No 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: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 940132528 Relay_Log_Space: 107 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: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4.' Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
日志:
120711 13:04:24 [Note] Slave I/O thread: connected to master '[email protected]:3306',replication started in log 'mysql-bin.000010' at position 940132528 120711 13:04:24 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position; the first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4. ( server_errno=1236) 120711 13:04:24 [ERROR] Slave I/O: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4.', Error_code: 1236 120711 13:04:24 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000010', position 940132528 120711 13:04:24 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 940132528, relay log './cb1s-relay-bin.000026' position: 940132674 120711 13:05:08 [Note] Error reading relay log event: slave SQL thread was killed 120711 13:06:20 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 940132528, relay log './cb1s-relay-bin.000027' position: 4
你不必创build一个新的奴隶。 你只需要重播master的数据,然后按照MySQL文档中的描述重新设置slave上的复制坐标( CHANGE MASTER TO ... )。
您可以通过为mysqldump调用指定–master-data = 2选项来停止数据库,从主服务器获取数据 – 这会将转储的复制坐标写入mysqldump输出。
请注意,运行mysqldump仍然意味着您的数据库支持应用程序的停机时间,因为在转储期间所有表都将被读取locking。
另一个select是按照David Schwartz在他对你的问题的评论中重置复制坐标,并使用Percona工具包中的pt-table-sync将所有表数据重播到从服务器,以确保完整性。