电脑技术网——专业手机电脑知识平台,关注科技、手机、电脑、智能硬件
MySQLMSSQLAccessOracle

MySQL中RESET SLAVE和RESET MASTER的区别

2021-01-22 12:30:40 出处:[ 菜菜电脑网 ] 人气:次阅读

 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

 

   

 

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

©CopyRight 2008-2020 caicaipc.com Inc All Rights Reserved.
菜菜电脑网 版权所有