星空网 > 软件开发 > 数据库

MySQL中RESET SLAVE和RESET MASTER的区别

 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的区别

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

美参议员致信亚马逊:应禁止零售商哄抬物价:https://www.ikjzd.com/articles/117221
亚马逊又将推出新站点?新市场又有何潜力?:https://www.ikjzd.com/articles/117222
亚马逊卖家:口罩之后,厕纸会是下一个爆款吗?:https://www.ikjzd.com/articles/117223
C2M模式为中国制造提出了创新发展思路:https://www.ikjzd.com/articles/117224
看完这个,秒懂C2M、P2P、P2C 、O2O 、B2C!:https://www.ikjzd.com/articles/117225
什么是c2m模式?Top10国内外C2m电商平台详细介绍:https://www.ikjzd.com/articles/117226
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
南美旅游报价(探索南美洲的旅行费用):https://www.vstour.cn/a/411234.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流