mysql主从备份注意的地方

首先需要做主从的数据库必须一模一样,如果你的数据库已经运行过一段时间,建议你先删除所有的二进制日志文件,包括索引xxx.index这个文件,否则重启mysql会出错。

从服务器上已经删除掉所有的二进制日志文件,当然包括一个master.info这个文件。这个文件是用来记录主服务器上过来的日志文件和记录位置的。如果你不删除它,它还会按照之前的记录来做,所以会出问题,我在这里浪费了很多时间了。

主服务器诊断:

show processlist;显示所有的进程。

show master status;显示主服务器的日志文件和指针位置。

mysql> show master status;
+------------------+----------+----------------+------------------+
File Position Binlog_Do_DB Binlog_Ignore_DB
+------------------+----------+----------------+------------------+
mysql-bin.000001 603 videoCommunity
+------------------+----------+----------------+------------------+
1 row in set (0.00 sec)

mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 603
Binlog_Do_DB: videoCommunity
Binlog_Ignore_DB:
1 row in set (0.00 sec)

如上图,mysql-bin.000001是日志记录文件,603是指针位置。

从服务器(slave)上诊断:

mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: master1
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 603
Relay_Log_File: master2-relay-bin.000053
Relay_Log_Pos: 740
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: videoCommunity
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: 603
Relay_Log_Space: 740
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
1 row in set (0.00 sec)

确认以上信息和主服务器是否一致。

Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 603

如果从服务器正常的会有

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

如果主服务器和从服务器部分同步失败,你可以确认一下是那里失败,当然你也可以略过这一步操作,使用

SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n; 忽略n部操作

START SLAVE;启动从服务

评论

此博客中的热门博文

在南京见到的农民工午饭情景

购买了iacces for iPad

在 Mac M1 CPU 上编译ffmpeg,并支持 opencl和videotoolbox