MySQL中關於RESET SLAVE和RESET MASTER的區別

來源:互聯網
上載者:User

標籤:

 RESET SLAVE的文法如下:

RESET SLAVE [ALL] [channel_option]channel_option:     FOR CHANNEL channel

 

其中,channel_option主要是針對5.7.6引入的多源複製。

 

RESET SLAVE

官方的解釋如下

RESET SLAVE makes the slave forget its replication position in the master‘s binary log. This statement is meant to be used for a clean start: It clears the master info and relay log info repositories, deletes all the relay log files, and starts a new relay log file. It also resets to 0 the replication delay specified with the MASTER_DELAY option to CHANGE MASTER TO. To use RESET SLAVE, the slave replication threads must be stopped (use STOP SLAVE if necessary).

其實,它是直接刪除master.info和relay-log.info檔案,並刪除所有的relay log,然後重建一個新的relay log,即使relay log中還有SQL沒有被SQL線程apply完。

但是

RESET SLAVE有個問題,它雖然刪除了上述檔案,但記憶體中的change master資訊並沒有刪除,此時,可直接執行start slave,但因為刪除了master.info和relay-log.info,它會從頭開始接受主的binlog並應用。

RESET SLAVE does not change any replication connection parameters such as master host, master port, master user, or master password, which are retained in memory. This means that START SLAVE can be issued without requiring a CHANGE MASTER TO statement following RESET SLAVE.

 

RESET SLAVE ALL

相對於RESET SLAVE,RESET SLAVE ALL還會刪除記憶體中的串連資訊,這個時候,執行start slave會報錯。

如下所示:

mysql> stop slave;Query OK, 0 rows affected (0.00 sec)mysql> reset slave all;Query OK, 0 rows affected (0.01 sec)mysql> start slave;ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO

 

注意:從MySQL 5.6.7開始,RESET SLAVE和RESET SLAVE ALL會對當前事務進行隱式提交。

 

RESET MASTER

Deletes all binary log files listed in the index file, resets the binary log index file to be empty, and creates a new binary log file.

刪除所有的二進位日誌,並重新建立一個新的二進位日誌

 

在GTID環境中,

RESET MASTER會清除掉系統變數gtid_purged和gtid_executed的值。

從MySQL 5.7.5開始,該語句同樣會清空mysql.gtid_executed的內容,該表儲存著GTID的資訊,這樣,在slave中可不用開啟binlog。

 

RESET MASTER和PURGE BINARY LOGS的區別

1. RESET MASTER會刪除所有的二進位日誌,而PURGE BINARY LOGS是一種基於時間點的刪除

   PURGE BINARY LOGS文法如下:

PURGE { BINARY | MASTER } LOGS    { TO ‘log_name‘ | BEFORE datetime_expr }

  譬如:

PURGE BINARY LOGS TO ‘mysql-bin.010‘;PURGE BINARY LOGS BEFORE ‘2008-04-02 22:46:26‘;

 

2. 在正常的主從複製環境中,如果在master上執行RESET MASTER,結果是不可預測的。但使用PURGE BINARY LOGS語句刪除binlog沒多大影響(前提是,刪除的binlog中的events已經傳輸到slave上)

 

參考

1. http://dev.mysql.com/doc/refman/5.7/en/reset-slave.html

2. http://dev.mysql.com/doc/refman/5.7/en/reset-master.html

3. http://dev.mysql.com/doc/refman/5.7/en/purge-binary-logs.html

 

   

 

MySQL中關於RESET SLAVE和RESET MASTER的區別

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.