当前位置:首页 > Mysql教程 > 列表

安全删除mysql主从复制二进制日志详解

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-04 17:25:17 浏览: 评论:0 

mysql主从设置之后如果操作不当删除A服务器B服务器上的数据会自动同步一并删除,如果这样删除错了就等于你没有备份数据库了,下面我来给大家介绍安全删除mysql主从复制二进制日志,大家可参考参考.

具体方法:删除日志之前,先检查主从服务器当前使用的日志文件,首先登录,要删除日志的服务器的 mysql 终端.

#mysql -u root -pxxxxx

检查复制主服务器状态:

  1. Mysql>show master status 
  2.  
  3. +------------------+-----------+--------------+----------------------------------------+ 
  4. | File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB                       | 
  5. +------------------+-----------+--------------+----------------------------------------+ 
  6. | mysql-bin.000097 | 541677824 | www      | test,mysql,information_schema | 
  7. +------------------+-----------+--------------+----------------------------------------+ 

复制主服务器当前正在使用的日志文件是:mysql-bin.000097,检查复制从服务器状态:

  1. Mysql>show slave statusG 
  2.  
  3. *************************** 1. row *************************** 
  4.                Slave_IO_State: Waiting for master to send event 
  5.                   Master_Host: 202.102.152.3 
  6.                   Master_User: replication 
  7.                   Master_Port: 3306 
  8.                 Connect_Retry: 60 
  9.               Master_Log_File: mysql-bin.000103 
  10.           Read_Master_Log_Pos: 675107897 
  11.                Relay_Log_File: www-relay-bin.000443 
  12.                 Relay_Log_Pos: 675097929 
  13.         Relay_Master_Log_File: mysql-bin.000103 
  14.              Slave_IO_Running: Yes 
  15.             Slave_SQL_Running: Yes 
  16.               Replicate_Do_DB: www 
  17.           Replicate_Ignore_DB: test,mysql,information_schema 
  18.            Replicate_Do_Table:  --phpfensi.com 
  19.        Replicate_Ignore_Table: 
  20.       Replicate_Wild_Do_Table: 
  21.   Replicate_Wild_Ignore_Table: 
  22.                    Last_Errno: 0 
  23.                    Last_Error: 
  24.                  Skip_Counter: 0 
  25.           Exec_Master_Log_Pos: 675107897 
  26.               Relay_Log_Space: 675098125 
  27.               Until_Condition: None 
  28.                Until_Log_File: 
  29.                 Until_Log_Pos: 0 
  30.            Master_SSL_Allowed: No 
  31.            Master_SSL_CA_File: 
  32.            Master_SSL_CA_Path: 
  33.               Master_SSL_Cert: 
  34.             Master_SSL_Cipher: 
  35.                Master_SSL_Key: 
  36.         Seconds_Behind_Master: 0 
  37. Master_SSL_Verify_Server_Cert: No 
  38.                 Last_IO_Errno: 0 
  39.                 Last_IO_Error: 
  40.                Last_SQL_Errno: 0 
  41.                Last_SQL_Error: 

复制从服务器当前正在使用的复制主服务器日志文件是:mysql-bin.000103,当前正在使用的日志文件是000097,我需要做的是删除00095号之前的所有日志(预留出最近几天的日志).

Mysql>purge master logs to ‘mysql-bin.000095;

#ll /usr/local/mysql/var/

从结果中发现,编号000097之前的所有日志都已经删除,如果还有其他服务器需要清理日志,重新按上面的顺序进行就可以.

Tags: mysql主从复制 mysql二进制日志

分享到: