从 mysql 复制失败中恢复的最佳方法是什么?

Ita*_*not 8 mysql replication mysqldump

今天,我们的主 mysql db 服务器和两个复制服务器之间的复制下降了。我在这里有一个很久以前写的程序,我不确定这是解决这个问题的最快方法。我想与您分享该程序,如果您能提出您的想法,甚至告诉我如何更快地完成,我将不胜感激。

At the master:

RESET MASTER;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
And copy the values of the result of the last command somewhere.

Wihtout closing the connection to the client (because it would release the read lock) issue the command to get a dump of the master:

mysqldump mysq
Now you can release the lock, even if the dump hasn't end. To do it perform the following command in the mysql client:

UNLOCK TABLES;
Now copy the dump file to the slave using scp or your preferred tool.

At the slave:

Open a connection to mysql and type:

STOP SLAVE;
Load master's data dump with this console command:

mysql -uroot -p < mysqldump.sql
Sync slave and master logs:

RESET SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
Where the values of the above fields are the ones you copied before.

Finally type

START SLAVE;
And to check that everything is working again, if you type

SHOW SLAVE STATUS;
you should see:

Slave_IO_Running: Yes
Slave_SQL_Running: Yes
That's it!
Run Code Online (Sandbox Code Playgroud)

目前我正处于将数据库从主服务器复制到其他两个复制服务器的阶段,到那时需要6个多小时,是不是太慢了?服务器通过 1GB 交换机连接。

小智 1

我们可以从停止的位置开始复制。您应该检查从属服务器日志上的 Mysql 日志,其中必须包含复制停止的最后一个 mysql bin 日志位置。

 STOP SLAVE;

 RESET Slave;

 FLUSH TABLES WITH READ LOCK;

 CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;

 Where the values of the above fields are the ones where replication stopped.  
Run Code Online (Sandbox Code Playgroud)

最后输入

 START SLAVE;
Run Code Online (Sandbox Code Playgroud)