mysql 复制 跳过_如何在MySQL复制中跳过某些错误

MySQL复制是好的,但是由于错误可能会停止,并且恢复工作复制可能很困难 - 您需要在主服务器上设置锁以获得一致的MySQL转储,并且在此期间网站不可访问。 但是,有一种方法可以使用slave-skip-errors伪指令忽略某些错误。

1初步说明

使用从属跳过错误,您可以使复制从站忽略某些错误代码(您可以在这里找到MySQL错误代码列表: 服务器错误代码和消息 )。 但是,您应该谨慎使用 - 它应该是您最后一个尝试恢复复制的工具,因为它可能使您的从站不一致。 您应该首先尝试以下方法之一: 如何修复MySQL复制或使用slave的my.cnf文件中的replicate-ignore-db或replicate-ignore-table语句来跳过导致复制失败的数据库/数据库表的复制(if您不需要这些数据库/数据库表的复制)。

2使用从属跳过错误

我们假设复制已经停止了,你在Minion的MySQL shell上得到这样的东西:

SHOW SLAVE STATUS \G

mysql> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 1.2.3.4

Master_User: slave_user

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000024

Read_Master_Log_Pos: 933201702

Relay_Log_File: mysqld-relay-bin.000113

Relay_Log_Pos: 63519994

Relay_Master_Log_File: mysql-bin.000021

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB: mysql,information_schema,performance_schema,test

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1054

Last_Error: Error 'Unknown column 'tx_feuserbranch_agb' in 'field list'' on query. Default database: 'dbtest'.

Query: 'INSERT INTO fe_users (email,first_name,last_name,address,ip,city,country,telephone,fax,company,tx_feuserbranch_brancha,

tx_feuserbranch_customernr,tx_feuserbranch_agb,username,password,name,usergroup,disable,by_invitation,tx_srfeuserregister_password,

tstap,crdate,cruser_id,fe_cruser_id,pid) VALUES ('test333@example.com','John','Doe','test','55555','test','Deutschland','49111111111',

'','test','0','55','on','test333@example.com','xxxxxxxxxxxxxx','John Doe','0','1','0','','1361359747','1361359747','0','0','33')'

Skip_Counter: 0

Exec_Master_Log_Pos: 120460827

Relay_Log_Space: 3500841420

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: Yes

Master_SSL_CA_File: /etc/mysql/newcerts/ca-cert.pem

Master_SSL_CA_Path:

Master_SSL_Cert: /etc/mysql/newcerts/client-cert.pem

Master_SSL_Cipher:

Master_SSL_Key: /etc/mysql/newcerts/client-key.pem

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 1054

Last_SQL_Error: Last_Error: Error 'Unknown column 'tx_feuserbranch_agb' in 'field list'' on query. Default database: 'dbtest'.

Query: 'INSERT INTO fe_users (email,first_name,last_name,address,ip,city,country,telephone,fax,company,tx_feuserbranch_brancha,

tx_feuserbranch_customernr,tx_feuserbranch_agb,username,password,name,usergroup,disable,by_invitation,tx_srfeuserregister_password,

tstap,crdate,cruser_id,fe_cruser_id,pid) VALUES ('test333@example.com','John','Doe','test','55555','test','Deutschland','49111111111',

'','test','0','55','on','test333@example.com','xxxxxxxxxxxxxx','John Doe','0','1','0','','1361359747','1361359747','0','0','33')'

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

1 row in set (0.00 sec)

mysql>

正如您在Last_Errno行中可以看到的,导致复制停止的错误的错误代码为1054( '%s'中的未知列'%s' )。 如果你想让MySQL从机忽略这样的错误,只需打开你的my.cnf(在Debian和Ubuntu上,它是/etc/mysql/my.cnf )...

vi /etc/mysql/my.cnf

...并添加line slave-skip-errors = 1054 :[...]

expire_logs_days = 10

max_binlog_size = 100M

server-id=2

replicate-ignore-db = mysql

replicate-ignore-db = information_schema

replicate-ignore-db = performance_schema

replicate-ignore-db = test

slave-skip-errors = 1054

[...]

之后重启MySQL:

/etc/init.d/mysql restart

再次登录MySQL

mysql -u root -p

...并再次检查Minion的状态 - 现在应该再次工作:

SHOW SLAVE STATUS \G

要让从设备忽略多个错误代码,只需用逗号分隔:

slave-skip-errors = 1062,1054

您可以在这里找到MySQL错误代码列表: 服务器错误代码和消息

3链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值