基于mysql数据库文件的主从同步与AB复制及数据备份之遇见问题的处理方法

255 阅读1分钟

本文已参与 ⌈新人创作礼⌋ 活动,一起开启掘金创作之路

基于mysql数据库文件的主从同步与AB复制及数据备份之遇见问题的处理方法

背景说明: 搭建实验环境说明
在 RH5.4 yum安装 mysql部署master 数据库A,Centos 5.5 编译安装mysql 部署slave数据库B;  
mysql 版本信息:   master  mysql-5.0.77    slave :mysql-5.0.87      
提示:(关闭selinux)

总结: 错误处理 ①

 对于       Slave_IO_Running: No                 Slave_SQL_Running: Yes  错误解答  

Master slave 复制错误
 Description:
 Slave_IO_Running:NO
 Slave_SQL_Running:Yes
 Seconds_Behind_Master: NULL
 本人遇到的Slave_IO_Running:NO的情况有下面两种:
 1. 在配置slave同步时因为slave访问master没有权限导致;
 2. master上的mysql-bin.xxxxxx文件全被我误删除了;
 对于第一种情况,仔细检查数据库访问权限即可解决;
 对于第二种情况:
 mysql> show slave status\G
 *************************** 1. row ***************************
              Slave_IO_State: 
                 Master_Host: 192.168.0.123
                 Master_User: slave
                 Master_Port: 3306
               Connect_Retry: 60
             Master_Log_File: mysql-bin.000016
         Read_Master_Log_Pos: 173
              Relay_Log_File: mysqld-relay-bin.000008
               Relay_Log_Pos: 98
       Relay_Master_Log_File: mysql-bin.000016
            Slave_IO_Running: No
           Slave_SQL_Running: Yes
             Replicate_Do_DB: 
         Replicate_Ignore_DB: 
          Replicate_Do_Table: 
      Replicate_Ignore_Table: br>          
                   Last_Error: 0
                Skip_Counter: 0
         Exec_Master_Log_Pos: 173
             Relay_Log_Space: 98
             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
 1 row in set (0.00 sec)
 解决步骤:
 重启master库:service mysqld restart
 mysql> show master status;
 +------------------+--------------------+----------------+------------------+
 | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 +------------------+-------------------+-----------------+------------------+
 | mysql-bin.000001 |       98 |              |                                         | 
 +------------------+--------------------+-----------------+------------------+
 mysql> slave stop;
 mysql> change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=98;
 mysql> slave start;
 mysql> show slave status\G
 *************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                 Master_Host: 192.168.0.123
                 Master_User: slave
                 Master_Port: 3306
               Connect_Retry: 60
             Master_Log_File: mysql-bin.000001
         Read_Master_Log_Pos: 98
              Relay_Log_File: mysqld-relay-bin.000002
               Relay_Log_Pos: 235
       Relay_Master_Log_File: mysql-bin.000001
            Slave_IO_Running: Yes
           Slave_SQL_Running: Yes
             Replicate_Do_DB: 
     Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
 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: 98
             Relay_Log_Space: 235
             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)

错误处理 ②

 问题:如果你的mysql数据库已经有数据存储使用,将导致master与slave日志错误!  

mysql> start slave;
 ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
 mysql> show slave status;
 Empty set (0.00 sec)
 处理:删除mysql-bin.000001 日志文件,并重启mysql服务
 1、master 
 #rm -rf /var/lib/mysql/*.*         
 2、slave 
 #rm -rf /usr/local/mysql/var/*.*    
 3、service mysqld restart