设为首页 加入收藏

TOP

Mysqlslave是否可以update?(一)
2018-12-12 16:11:52 】 浏览:362
Tags:Mysqlslave 是否 可以 update
最近平台要做迁移,由于业务迁移过程需求,希望slave在平台迁移过程中,既能保证master的数据同步到slave,但是也希望slave可以update.

这个需求,作为DBA,单单从数据库层面,基本可以判断,是不可行的.但是,实际测试,才有说服力.用数据/实验结果说话。

开始着手搭建一个测试的主从,进行slave的update测试.

将slave的read_only设置为on,让slave是可以更改的.这里需要注意.read_only这个参数.对于root或者拥有(.) 全instance权限的用户,是不生效的.

主库创建一个测试表test2

在slave上,可以看到test2已经同步过来

查询表行数

mysql> select count(*) from test2;

+----------+

| count(*) |

+----------+

| 23502 |

+----------+

1 row in set (0.01 sec)

删除10行

mysql> delete from test2 where id<10;

Query OK, 9 rows affected (0.04 sec)

再次查询表行数

mysql> select count(*) from test2;

+----------+

| count(*) |

+----------+

| 23493 |

+----------+

1 row in set (0.01 sec)

在主库,修改表数据

mysql> select count(*) from test2;

+----------+

| count(*) |

+----------+

| 23502 |

+----------+

1 row in set (0.01 sec)

删除5行数据

mysql> delete from test2 where id<5;

Query OK, 4 rows affected (0.04 sec)

查询行数

mysql> select count(*) from test2;

+----------+

| count(*) |

+----------+

| 23498 |

+----------+

1 row in set (0.01 sec)

再到备库,查看同步状态

mysql> show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 10.27.20.4

Master_User: envision

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000043

Read_Master_Log_Pos: 57380204

Relay_Log_File: replay-bin.000003

Relay_Log_Pos: 320

Relay_Master_Log_File: mysql-bin.000043

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: 1032

Last_Error: Could not execute Delete_rows event on table cnpmjs.test2; Can't find record in 'test2', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000043, end_log_pos 57380173

Skip_Counter: 0

Exec_Master_Log_Pos: 57375790

Relay_Log_Space: 13539720

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: 1032

Last_SQL_Error: Could not execute Delete_rows event on table cnpmjs.test2; Can't find record in 'test2', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000043, end_log_pos 57380173

Replicate_Ignore_Server_Ids:

Master_Server_Id: 102

Master_UUID: b095e989-7dcf-11e8-83a2-0017fa032e39

Master_Info_File: /var/lib/mysql/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: 180702 14:54:00

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

上面错误,已经说明,主从的数据已经不一致,无法继续同步

在slave上修复数据,插入缺少的10行

mysql> insert into test2 select * from user where id<10;

Query OK, 9 rows affected (0.01 sec)

Records: 9 Duplicates: 0 Warnings: 0

修改完成之后,重启slave进程

mysql> stop slave;

Query OK, 0 rows affected (0.00 sec)

mysql> start slave;

Query OK, 0 rows affected (0.01 sec)

再次查询,可以看到,slave又继续

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇redis数据迁移 下一篇创建原始数据库

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目