企业生产场景mysql主从复制故障原因
实验一:
目的:解决主从不同步(本例中sql线程出现问题)
方法:模拟故障场景
1.在SLAVE上建立一个名为yingying数据库。
mysql> create database yingying;
2.在MASTER上建立一个名为yingying数据库。
mysql> create database yingying;
3.查看SALVE上的状态。
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.254.253
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 384
Relay_Log_File: localhost-relay-bin.000010
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000004
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: 1007 //mysql错误代码
Last_Error: Error 'Can't create database 'yingying'; database exists' on query. Default database:
'yingying'. Query: 'create database yingying'
Skip_Counter: 0
Exec_Master_Log_Pos: 293
Relay_Log_Space: 504
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: 1007
Last_SQL_Error: Error 'Can't create database 'yingying'; database exists' on query. Default database:
'yingying'. Query: 'create database yingying'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
4.解决措施:
mysql > stop slave;
mysql>set global sql_slave_skip_counter=1; //往下跳一个指针,1可以更换其他数字,数字越大,丢失的数据越
多。
mysql >start slave;
注释:对于普通的互联网业务,忽略问题不是很大。当然要确认不影响公司业务的前提下。
企业场景解决主从同步,比主从不一致对当前更重要,然后如果主从数据一致也很重要,在找个时间恢复下这个
从库。
主从数据不一致更重要还是主从同步持续状态更重要。根据业务选择。
5.验证:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.254.253
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 384
Relay_Log_File: localhost-relay-bin.000011
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000004
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: 384
Relay_Log_Space: 650
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: 1
1 row in set (0.00 sec)
----------------------------------------------------------------------------------------------
实验二:
目的:主从不同步(通过忽略错误号)
方法:1. 在my.cnf配置文件中mysqld中,增加忽略语句
slave-skip-errors = 1032,1062,1007 //错误号可以查询mysql错误代码
2.重启mysql数据库
3.在SLAVE中建立一个数据库 //验证
4.在MASTER中建立一个数据库 //验证
5.查看SLAVE状态 : show slave status;
注释:不同的数据库版本会引起不同步,低版本到高版本可以,但是高版本不能往低版本同步。
转载于:https://blog.51cto.com/xin521long/1832333