如何乾淨的清除Slave同步資訊【小技巧】

來源:互聯網
上載者:User

 
  1. mysql> show slave status\G; 
  2. *************************** 1. row *************************** 
  3.                Slave_IO_State: Waiting for master to send event 
  4.                   Master_Host: 192.168.8.22 
  5.                   Master_User: repl 
  6.                   Master_Port: 3306 
  7.                 Connect_Retry: 10 
  8.               Master_Log_File: mysql-bin.000015 
  9.           Read_Master_Log_Pos: 107 
  10.                Relay_Log_File: vm02-relay-bin.000025 
  11.                 Relay_Log_Pos: 253 
  12.         Relay_Master_Log_File: mysql-bin.000015 
  13.              Slave_IO_Running: Yes 
  14.             Slave_SQL_Running: Yes 
  15.               Replicate_Do_DB:  
  16.           Replicate_Ignore_DB:  
  17.            Replicate_Do_Table:  
  18.        Replicate_Ignore_Table:  
  19.       Replicate_Wild_Do_Table:  
  20.   Replicate_Wild_Ignore_Table:  
  21.                    Last_Errno: 0 
  22.                    Last_Error:  
  23.                  Skip_Counter: 0 
  24.           Exec_Master_Log_Pos: 107 
  25.               Relay_Log_Space: 554 
  26.               Until_Condition: None 
  27.                Until_Log_File:  
  28.                 Until_Log_Pos: 0 
  29.            Master_SSL_Allowed: No 
  30.            Master_SSL_CA_File:  
  31.            Master_SSL_CA_Path:  
  32.               Master_SSL_Cert:  
  33.             Master_SSL_Cipher:  
  34.                Master_SSL_Key:  
  35.         Seconds_Behind_Master: 0 
  36. Master_SSL_Verify_Server_Cert: No 
  37.                 Last_IO_Errno: 0 
  38.                 Last_IO_Error:  
  39.                Last_SQL_Errno: 0 
  40.                Last_SQL_Error:  
  41.   Replicate_Ignore_Server_Ids:  
  42.              Master_Server_Id: 22 
  43. 1 row in set (0.03 sec) 
  44.  
  45. ERROR:  
  46. No query specified 

現在由於業務的需要,不需要這台Slave同步複製Master,那麼採用reset slave時,你會發現同步資訊還存在,如:

 
  1. mysql> stop slave; 
  2. Query OK, 0 rows affected (0.19 sec) 
  3.  
  4. mysql> reset slave; 
  5. Query OK, 0 rows affected (0.17 sec) 
  6.  
  7. mysql> show slave status\G; 
  8. *************************** 1. row *************************** 
  9.                Slave_IO_State:  
  10.                   Master_Host: 192.168.8.22 
  11.                   Master_User: repl 
  12.                   Master_Port: 3306 
  13.                 Connect_Retry: 10 
  14.               Master_Log_File:  
  15.           Read_Master_Log_Pos: 4 
  16.                Relay_Log_File: vm02-relay-bin.000001 
  17.                 Relay_Log_Pos: 4 
  18.         Relay_Master_Log_File:  
  19.              Slave_IO_Running: No 
  20.             Slave_SQL_Running: No 
  21.               Replicate_Do_DB:  
  22.           Replicate_Ignore_DB:  
  23.            Replicate_Do_Table:  
  24.        Replicate_Ignore_Table:  
  25.       Replicate_Wild_Do_Table:  
  26.   Replicate_Wild_Ignore_Table:  
  27.                    Last_Errno: 0 
  28.                    Last_Error:  
  29.                  Skip_Counter: 0 
  30.           Exec_Master_Log_Pos: 0 
  31.               Relay_Log_Space: 126 
  32.               Until_Condition: None 
  33.                Until_Log_File:  
  34.                 Until_Log_Pos: 0 
  35.            Master_SSL_Allowed: No 
  36.            Master_SSL_CA_File:  
  37.            Master_SSL_CA_Path:  
  38.               Master_SSL_Cert:  
  39.             Master_SSL_Cipher:  
  40.                Master_SSL_Key:  
  41.         Seconds_Behind_Master: NULL 
  42. Master_SSL_Verify_Server_Cert: No 
  43.                 Last_IO_Errno: 0 
  44.                 Last_IO_Error:  
  45.                Last_SQL_Errno: 0 
  46.                Last_SQL_Error:  
  47.   Replicate_Ignore_Server_Ids:  
  48.              Master_Server_Id: 22 
  49. 1 row in set (0.02 sec) 
  50.  
  51. ERROR:  
  52. No query specified 

執行reset slave,其實是把master.info和relay-log.info檔案給刪除,但裡面的同步資訊還在,那麼可以用這個方法,讓其清除的徹徹底底。

 
  1. mysql> reset slave all; 
  2. Query OK, 0 rows affected (0.04 sec) 
  3.  
  4. mysql> show slave status\G; 
  5. Empty set (0.02 sec) 
  6.  
  7. ERROR:  
  8. No query specified 

650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131228/2256451525-0.jpg" />

註:此語句支援在MySQL5.5或更高版本。

本文出自 “賀春暘的技術專欄” 部落格,請務必保留此出處http://hcymysql.blog.51cto.com/5223301/1183656

相關文章

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.