MySQL master-slave replication Solution

Source: Internet
Author: User

 

This is the configuration of the master database for master-slave replication in mysql:
 

 
 
  1. server-id       = 1  
  2. log-bin=/mysql_log/binlog/bin-log  
  3. slave-skip-errors=1062,1205  
  4. max_binlog_size = 500M  
  5. binlog_cache_size = 128K  
  6. relay-log =/mysql_log/relaylog/relaylog  
  7. log-slave-updates 

The master-slave replication of MySQL built earlier has a problem and cannot be synchronized normally. Check the log and send the following error:

 
 
  1. 120726 13:20:36 Could not use /mysql_log/relaylog/relaylog for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.  
  2. 120726 13:20:36 Failed in open_log() called from init_relay_log_info()  
  3. 120726 13:20:36 Failed to initialize the master info structure  
  4. 120726 13:20:36 Could not use /mysql_log/binlog/bin-log for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.  
  5.  
  6.  
  7. 120801 17:53:00 Failed to open the relay log '/mysql_log/relaylog/relaylog.036' (relay_log_pos 4)  
  8. 120801 17:53:00 Could not find target log during relay log initialization  
  9. 120801 17:53:00 Failed to initialize the master info structure  
  10.  

1. Disable mysql

 
 
  1. [root@111_ddb ~]# mysqladmin -p shutdown  
  2. Enter password:  
  3.  
  4. [root@111_ddb data]# tail -f /home/mysql/data/111_ddb.err  
  5. 120801 17:56:57 /usr/local/mysql/libexec/mysqld: Normal shutdown  
  6.  
  7. 120801 17:56:58  InnoDB: Starting shutdown...  
  8. 120801 17:57:30  InnoDB: Shutdown completed  
  9. 120801 17:57:30 /usr/local/mysql/libexec/mysqld: Shutdown Complete  
  10.  
  11. 120801 17:57:30  mysqld ended  

2. Delete the binlog record file, msater.info and relay-log.info on the master database

 
 
  1. [root@111_ddb ~]# cd /home/mysql/data/  
  2. [root@111_ddb data]# ls  
  3. 111_ddb.err  111_ddb-slow.log  ddb                     ibdata1      ib_logfile1  master.info  mysql_dd        slow.log  test  
  4. 111_ddb.pid  adb               ib_arch_log_0000000000  ib_logfile0  ib_logfile2  mysql        relay-log.info  tdb  
  5. [root@111_ddb data]# ls *info  
  6. master.info  relay-log.info  
  7. [root@111_ddb data]# ls  
  8. 111_ddb.err  111_ddb-slow.log  ddb                     ibdata1      ib_logfile1  master.info  mysql_dd        slow.log  test  
  9. 111_ddb.pid  adb               ib_arch_log_0000000000  ib_logfile0  ib_logfile2  mysql        relay-log.info  tdb  
  10. [root@111_ddb data]# rm -f master.info relay-log.info   
  11. [root@111_ddb data]# cd /mysql_log/binlog/  
  12. [root@111_ddb binlog]# ls  
  13. bin-log.001  bin-log.index 
  14. [root@111_ddb binlog]# rm -f *  
  15. [root@111_ddb binlog]# cd ../relaylog/  
  16. [root@111_ddb relaylog]# ls  
  17. relaylog.001  relaylog.index 
  18. [root@111_ddb relaylog]# rm -f *  
  19. [root@111_ddb relaylog]# cd ../binlog/ 

3. Enable mysql

 
 
  1. [root@111_ddb ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/innodb.cnf --datadir=/home/mysql/data --user=mysql &  
  2.  
  3. [root@111_ddb data]# tail -f /home/mysql/data/111_ddb.err  
  4.  
  5. 120801 17:58:21  mysqld started  
  6. 120801 17:58:23  InnoDB: Started  
  7. /usr/local/mysql/libexec/mysqld: ready for connections.  
  8. Version: '4.0.26-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution  
  9.  
  10. [root@111_ddb binlog]# ll  
  11. total 13080  
  12. -rw-rw---- 1 mysql mysql 13365795 Aug  1 17:59 bin-log.001  
  13. -rw-rw---- 1 mysql mysql       30 Aug  1 17:58 bin-log.index  
  14. [root@111_ddb binlog]# ll  
  15. total 13828  
  16. -rw-rw---- 1 mysql mysql 14132046 Aug  1 17:59 bin-log.001  
  17. -rw-rw---- 1 mysql mysql       30 Aug  1 17:58 bin-log.index  
  18. [root@111_ddb binlog]# ll  
  19. total 15020  
  20. -rw-rw---- 1 mysql mysql 15355877 Aug  1 17:59 bin-log.001  
  21. -rw-rw---- 1 mysql mysql       30 Aug  1 17:58 bin-log.index 

By logging and viewing the binlog file, the configuration of the master database is restored to normal.
 

This article from the "open source one member" blog, please be sure to keep this source http://521cto.blog.51cto.com/950229/951776

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.