stop slave->reset slave->start slave 复制从哪个位置开始?reset slave all呢?
reset slave
首先来看下当前master-slave情况
mysql> prompt \u@\h,\p:\d>\_
PROMPT set to '\u@\h,\p:\d>\_' # master
mydba@192.168.85.129,3306:test> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec) # slave
mydba@192.168.85.129,3307:test> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.85.129
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 120
Relay_Log_File: mysql-relay-bin.000011
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
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: 120
Relay_Log_Space: 15247
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: 0
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: 6
Master_UUID: 02a05b2c-0557-11e7-bb02-000c29493a20
Master_Info_File: /usr/local/mysql3307/log/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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:
Auto_Position: 0
1 row in set (0.00 sec)
此时主从处于同步状态,接着在从库上执行reset slave,并查看同步情况
# slave
mydba@192.168.85.129,3307:test> stop slave;
Query OK, 0 rows affected (0.20 sec) mydba@192.168.85.129,3307:test> reset slave;
Query OK, 0 rows affected (0.07 sec) mydba@192.168.85.129,3307:test> start slave;
Query OK, 0 rows affected (0.05 sec) mydba@192.168.85.129,3307:test> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.85.129
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 120
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
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: 1051
Last_Error: Error 'Unknown table 'test.a'' on query. Default database: 'test'. Query: 'DROP TABLE `a` /* generated by server */'
Skip_Counter: 0
Exec_Master_Log_Pos: 120
Relay_Log_Space: 498471
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: 1051
Last_SQL_Error: Error 'Unknown table 'test.a'' on query. Default database: 'test'. Query: 'DROP TABLE `a` /* generated by server */'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 6
Master_UUID: 02a05b2c-0557-11e7-bb02-000c29493a20
Master_Info_File: /usr/local/mysql3307/log/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: 170719 15:35:08
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
Slave_IO_Running: I/O线程是否启动并且成功连接到master
Slave_SQL_Running: SQL线程是否启动
Master_Log_File:I/O线程当前正在读取的主服务器二进制日志文件的名称
Read_Master_Log_Pos:在当前的主服务器二进制日志中,I/O线程已经读取的位置
Relay_Log_File:SQL线程当前正在读取和执行的中继日志文件的名称
Relay_Log_Pos:在当前的中继日志中,SQL线程已读取和执行的位置
Relay_Master_Log_File:包含SQL线程最近执行的事件的主服务器二进制日志文件的名称
Exec_Master_Log_Pos:在主服务器二进制日志中(Relay_Master_Log_File),SQL线程已执行的位置。主服务器的二进制日志中的(Relay_Master_Log_File,Exec_Master_Log_Pos)对应于在中继日志中的(Relay_Log_File,Relay_Log_Pos)
从上面结果可知,SQL线程已经停止;SQL线程已经执行的主服务器二进制日志文件的名称mysql-bin.000001,SQL线程已执行的位置120
主库查看二进制日志
# master
mydba@192.168.85.129,3306:test> show binlog events in 'mysql-bin.000001';
+------------------+------+-------------+-----------+-------------+------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+------+-------------+-----------+-------------+------------------------------------------------------------+
| mysql-bin.000001 | 4 | Format_desc | 6 | 120 | Server ver: 5.6.35-log, Binlog ver: 4 |
| mysql-bin.000001 | 120 | Query | 6 | 234 | use `test`; DROP TABLE `a` /* generated by server */ |
| mysql-bin.000001 | 234 | Query | 6 | 319 | use `test`; flush general logs |
| mysql-bin.000001 | 319 | Query | 6 | 404 | use `test`; flush general logs |
| mysql-bin.000001 | 404 | Query | 6 | 501 | use `test`; create table aaa(a int) |
| mysql-bin.000001 | 501 | Query | 6 | 617 | use `test`; DROP TABLE `aaa` /* generated by server */ |
| mysql-bin.000001 | 617 | Query | 6 | 737 | use `test`; DROP TABLE `bittest` /* generated by server */ |
| mysql-bin.000001 | 737 | Query | 6 | 853 | use `test`; DROP TABLE `tb1` /* generated by server */ |
| mysql-bin.000001 | 853 | Query | 6 | 969 | use `test`; DROP TABLE `tb2` /* generated by server */ |
| mysql-bin.000001 | 969 | Query | 6 | 1086 | use `test`; DROP TABLE `test` /* generated by server */ |
| mysql-bin.000001 | 1086 | Query | 6 | 1187 | use `test`; create table credro(id int) |
| mysql-bin.000001 | 1187 | Query | 6 | 1306 | use `test`; DROP TABLE `credro` /* generated by server */ |
| mysql-bin.000001 | 1306 | Query | 6 | 1407 | use `test`; create table credro(id int) |
| mysql-bin.000001 | 1407 | Query | 6 | 1526 | use `test`; DROP TABLE `credro` /* generated by server */ |
| mysql-bin.000001 | 1526 | Stop | 6 | 1549 | |
+------------------+------+-------------+-----------+-------------+------------------------------------------------------------+
15 rows in set (0.00 sec) mydba@192.168.85.129,3306:test> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 1549 |
| mysql-bin.000002 | 143 |
| mysql-bin.000003 | 143 |
| mysql-bin.000004 | 480108 |
| mysql-bin.000005 | 143 |
| mysql-bin.000006 | 14771 |
| mysql-bin.000007 | 120 |
+------------------+-----------+
7 rows in set (0.00 sec)
Log_name=mysql-bin.000001,Pos=120对应的是语句是use `test`; DROP TABLE `a`;其后还有很多操作语句。
由此可知,stop slave->reset slave->start slave 它的连接信息没有丢失,只是同步的起始位置发生了变化,之前执行过的操作还需再次执行导致同步异常。
为了后续操作直接使用change master到master status位置
# slave
mydba@192.168.85.129,3307:test> stop slave;
Query OK, 0 rows affected (0.01 sec) mydba@192.168.85.129,3307:test> change master to
-> master_host='192.168.85.129',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000007',
-> master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.04 sec) mydba@192.168.85.129,3307:test> start slave;
Query OK, 0 rows affected (0.02 sec)
reset slave all
首先来看下当前master-slave情况
# master
mydba@192.168.85.129,3306:test> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec) # slave
mydba@192.168.85.129,3307:test> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.85.129
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 120
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
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: 120
Relay_Log_Space: 456
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: 0
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: 6
Master_UUID: 02a05b2c-0557-11e7-bb02-000c29493a20
Master_Info_File: /usr/local/mysql3307/log/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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:
Auto_Position: 0
1 row in set (0.00 sec)
此时主从处于同步状态,接着在从库上执行reset slave all,并查看同步情况
# slave
mydba@192.168.85.129,3307:test> stop slave;
Query OK, 0 rows affected (0.00 sec) mydba@192.168.85.129,3307:test> reset slave all;
Query OK, 0 rows affected (0.01 sec) mydba@192.168.85.129,3307:test> start slave;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
使用change master to
mydba@192.168.85.129,3307:test> change master to
-> master_host='192.168.85.129',
-> master_port=3306,
-> master_user='repl',
-> master_password='repl',
-> master_log_file='mysql-bin.000007',
-> master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.02 sec) mydba@192.168.85.129,3307:test> start slave;
Query OK, 0 rows affected (0.01 sec)
参考网上的说法reset slave和reset slave all所做的操作如下
1、删除master.info和relay-log.info文件;
2、删除所有的relay log(包括还没有应用完的日志),创建一个新的relay log文件;
如果不加all参数,那么所有的连接信息仍然保留在内存中,包括主库地址、端口、用户、密码等。这样可以直接运行start slave命令而不必重新输入change master to命令,而运行show slave status也仍和没有运行reset slave一样,有正常的输出(ShanFish补充:运行show slave status有输出,但里面的取值有变化,部分同步会出现异常)。但如果加了all参数,那么这些内存中的数据也会被清除掉,运行show slave status输出为空。
如果主服务器部分二进制日志删除(expire_logs_days),比如mysql-bin.000001被删除,那么reset slave后再启动会指向哪个位置?
stop slave->reset slave->start slave 复制从哪个位置开始?reset slave all呢?的更多相关文章
- 解读show slave status 命令判断MySQL复制同步状态
解读show slave status 命令判断MySQL复制同步状态 1. show slave status命令可以显示主从同步的状态 MySQL> show slave status \G ...
- show slave status 命令判断MySQL复制同步状态
1. show slave status命令可以显示主从同步的状态 MySQL> show slave status \G; *************************** 1. row ...
- 问题解决——VS2010 将生成的文件复制到指定位置
我是从VC6直接过渡到VS2010的,VS2008没怎么用过.用VS2010的时候,每次生成dll后,手工把dll.lib..h文件复制到指定文件夹太麻烦了,所以着手写了这个. =========== ...
- maven将依赖的jar包复制到指定位置
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- 九、创建Slave节点
通常情况下,我们的项目会由多个模块或者系统组成,不同模块可能会分别部署在不同的服务器,比如mod1部署在ser1,mod2部署在ser2上: 之前的文档是描述了将jenkins也部署在ser1上,当m ...
- 涂抹mysql笔记-mysql复制特性
<>mysql复制特性:既可以实现整个服务(all databases)级别的复制,也可以只复制某个数据库或某个数据库中的某个指定的表对象.即可以实现A复制到B(主从单向复制),B再复制到 ...
- Mysql基于GTID复制模式-运维小结 (完整篇)
先来看mysql5.6主从同步操作时遇到的一个报错:mysql> change master to master_host='192.168.10.59',master_user='repli' ...
- MYSQL 复制详解
MySql 复制介绍 MySQL复制允许将主实例(master)上的数据同步到一个或多个从实例(slave)上,默认情况 下复制是异步进行的,从库也不需要一直连接到主库来同步数据 MySQL复制的数据 ...
- 基于jenkins搭建一个持续集成服务器
1 引言 1.1 编写目的 指导质量管理部,业务测试组同事进行Jenkins环境部署,通过Jenkins解决测试环境不可控,开发测试环境不一致等问题. 1.2 使用对象 质量管理部.基础研发部,集成部 ...
随机推荐
- NX二次开发-UFUN获取显示在NX交互界面的对象UF_OBJ_is_displayable
NX9+VS2012 #include <uf.h> #include <uf_disp.h> #include <uf_obj.h> #include <u ...
- 对A盾原理的小小总结,膜拜A神
A盾的原理是在驱动加载时重载os内核,获取原始ssdt表的地址. 应用层点击查询的代码在文件A-ProtectView.cpp中,每种点击操作调用相应的 query查询函数,在query函数里 Rea ...
- [转] undefined reference to `clock_gettime'
下面这个错误通常是因为链接选项里漏了-lrt,但有时发现即使加了-lrt仍出现这个问题,使用nm命令一直,会发现-lrt最终指向的文件 没有包含任何symbol,这个时候,可以找相应的静态库版本lib ...
- jsp-解决自写Servlet老是报错404
写好servlet进行测试老是报404解决方案. 1.确保web.xml配置好 2.Bulid Path项目,在Libraries界面Add External JARs,在tomcat的lib目录下面 ...
- VS新建工程或者新建项时 出现未定义标识符号
VS新建工程或者新建项时 出现未定义标识符号,编译之后不影响运行,但是看着很不舒服,影响效率. 解决办法:属性--->VC++目录-->包含目录-->编辑,将自己所用QT的inclu ...
- Mysql 插入数据,随机事件选择
在拼写sql的 时候,mysql字段如果需要添加当前时间可以用NOW() 函数 // String sql = ("insert into tablename(content, create ...
- python 19 lambda函数
转自http://www.cnblogs.com/BeginMan/p/3178103.html 一.lambda函数 1.lambda函数基础: lambda函数也叫匿名函数,即,函数没有具体的名称 ...
- 大道浮屠诀---mysql5.7.28 for linux安装
环境: redhat6.5 MySQL Community Server 5.7.28 https://dev.mysql.com/downloads/mysql/5.7.html 安装RMP包的具体 ...
- Reverses CodeForces - 906E (最小回文分解)
题意: 给你两个串s和t,其中t是由s中选择若干个不相交的区间翻转得到的,现在要求求出最少的翻转次数以及给出方案. 1≤|s|=|t|≤500000 题解: 我们将两个字符串合成成T=s1t1s2t2 ...
- ThreadPoolTaskExecutor的配置使用
版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/ft305977550/article/de ...