Wednesday, January 27, 2016

Erase Replication and Slave Settings and Data on MySQL slave

To erase all replication data on MySQL you can do: MySQL 5.0 and 5.1:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='';
MySQL 5.5 and 5.6:
STOP SLAVE;
RESET SLAVE ALL;
example:
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: SOMEHOST
                  Master_User: MASTER_USER
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: mysql-relay-bin.000004
                Relay_Log_Pos: 2949
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          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: 0
              Relay_Log_Space: 0
              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
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID: 0b505dc2-c3e3-11e5-8adf-000c292bd8a9
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: c042d2a4-3ba4-ee1a-69aa-b4b5a00d8fe3:1-2027
                Auto_Position: 0
1 row in set (0.00 sec)

mysql> reset slave all;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status;
Empty set (0.00 sec)
Remember that "RESET SLAVE" only reset the replication "Exec_Master_Log_Pos", " Read_Master_Log_Pos" and "binlog".

No comments:

Post a Comment