![MySQL 复制恢复](https://linux22.com/image/589771/MySQL%20%E5%A4%8D%E5%88%B6%E6%81%A2%E5%A4%8D.png)
主服务器崩溃后,我无法同步从属服务器。您能否告知是否可以恢复(不丢失数据/事务)或者我是否必须创建新的从属服务器?
请注意,出现此错误后我停止了从属操作:
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
答案1
你不必创造一个新的从服务器。你只需要重放主服务器的数据,并在从服务器上重新设置复制坐标(CHANGE MASTER TO ...
)即可MySQL 文档中描述。
您可以通过指定--主数据=2选项到你的 mysqldump 调用 - 这会将你的转储的复制坐标写入输出中mysqldump
。
请注意,运行 mysqldump可以仍然意味着数据库支持的应用程序的停机时间,因为在转储期间所有表都将被读锁定。
另一个选择是重置复制坐标David Schwartz 在对你的问题的评论中建议并使用以下方式将所有表的数据重播到从属服务器Percona Toolkit 中的 pt-table-sync以确保完整性。