MySQL RESET MASTER与RESET SLAVE

RESET MASTER
删除所有index file 中记录的所有binlog 文件,将日志索引文件清空,创建一个新的日志文件,这个命令通常仅仅用于第一次用于搭建主从关系的时的主库。

注意reset master 不同于purge binary log的两处地方
1. reset master 将删除日志索引文件中记录的所有binlog文件,创建一个新的日志文件 起始值从000001 开始,然而purge binary log 命令并不会修改记录binlog的顺序的数值
2. reset master 不能用于有任何slave 正在运行的主从关系的主库。因为在slave 运行时刻 reset master 命令不被支持,reset master 将master 的binlog从000001 开始记录,slave 记录的master log 则是reset master 时主库的最新的binlog,从库会报错无法找的指定的binlog文件。

In MySQL 5.6.5 and later, RESET MASTER also clears the values of the gtid_purged system variable (known as gtid_lost in MySQL 5.6.8 and earlier) as well as the global value of the gtid_executed (gtid_done, prior to MySQL 5.6.9) system variable (but not its session value); that is, executing this statement sets each of these values to an empty string (”)

RESET SLAVE
reset slave 将使slave 忘记主从复制关系的位置信息。该语句将被用于干净的启动, 它删除master.info文件和relay-log.info 文件以及所有的relay log 文件并重新启用一个新的relaylog文件。

使用reset slave之前必须使用stop slave 命令将复制进程停止。

注意:所有的relay log将被删除不管他们是否被SQL thread进程完全应用(这种情况发生于备库延迟以及在备库执行了stop slave 命令),存储复制链接信息的master.info文件将被立即清除,如果SQL thread 正在复制临时表的过程中,执行了stop slave ,并且执行了reset slave,这些被复制的临时表将被删除。

RESET SLAVE ALL
在 5.6 版本中 reset slave 并不会清理存储于内存中的复制信息比如 master host, master port, master user, or master password,也就是说如果没有使用change master 命令做重新定向,执行start slave 还是会指向旧的master 上面。

当从库执行reset slave之后,将mysqld shutdown 复制参数将被重置。

在5.6.3 版本以及以后 使用使用 RESET SLAVE ALL 来完全的清理复制连接参数信息。(Bug #11809016)
RESET SLAVE ALL does not clear the IGNORE_SERVER_IDS list set by CHANGE MASTER TO. This issue is fixed in MySQL 5.7. (Bug #18816897)
In MySQL 5.6.7 and later, RESET SLAVE causes an implicit commit of an ongoing transaction. See Section 13.3.3, “Statements That Cause an Implicit Commit”.

参考
http://dev.mysql.com/doc/refman/5.6/en/reset-master.html
http://dev.mysql.com/doc/refman/5.6/en/reset-slave.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I don't have the ability to physically reset a MySQL master server, but I can provide the general steps that can be followed to reset a MySQL master server: 1. Stop the MySQL service on the master server using the command "systemctl stop mysql" (for systems using systemd) or "service mysql stop" (for systems using init.d). 2. Edit the MySQL configuration file (usually located at /etc/mysql/my.cnf) and add the following lines under the [mysqld] section: skip-slave-start log-bin = /var/log/mysql/mysql-bin.log server-id = 1 These lines will disable the replication (skip-slave-start), enable binary logging (log-bin), and set the server ID to 1. 3. Delete the binary log files and the relay log files from the data directory (usually located at /var/lib/mysql). You can do this by running the command "rm -rf /var/lib/mysql/*-bin.*". 4. Start the MySQL service using the command "systemctl start mysql" or "service mysql start". 5. Connect to the MySQL server using the command "mysql -u root -p" and run the following commands: RESET MASTER; FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; These commands will reset the binary log, flush the tables, and show the current master status. 6. Take note of the file name and position from the output of the SHOW MASTER STATUS command. 7. Exit the MySQL shell by running the command "exit". 8. Update the slave servers with the new master information by running the following command on each slave server: CHANGE MASTER TO MASTER_HOST='master_hostname', MASTER_USER='replication_user', MASTER_PASSWORD='replication_password', MASTER_LOG_FILE='master_log_file_name', MASTER_LOG_POS=master_log_file_position; Replace the values inside the single quotes with the appropriate values for your setup. 9. Start the replication on each slave server using the command "START SLAVE;". That's it! Your MySQL master server should now be reset and ready for replication.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值