mysql sql_log_bin运用实例

来源:互联网 发布:2017办公室软件下载 编辑:程序博客网 时间:2024/06/03 18:09

参考网址:

http://blog.itpub.net/22664653/viewspace-720582/

环境信息:

master: 192.168.0.100  

master: 192.168.0.101 

1.版本 信息:

admin@localhost : test 04:03:40> select @@version;
+------------+
| @@version  |
+------------+
| 5.5.24-log |
+------------+

2.测试过程

(1) 创建测试表t1;

CREATE TABLE `t1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

(2) 插入如下数据:

| id         | name  |
+------------+-------+
| 2147483647 | wxx   |
| 2147483648 | liujf |
| 4294967294 | tjj |
| 4294967295 | canjj |

此时的ID已经为最大,再插入就报错误了,如下所示:

admin@localhost : test 03:51:08> insert into t1 values(4294967296,'tanjj');
ERROR 1062 (23000): Duplicate entry '4294967295' for key 'PRIMARY'
Warning (Code 1264): Out of range value for column 'id' at row 1

(3)先在备库上执行如下语句:

admin@localhost : test 03:51:16> set sql_log_bin=0;

admin@localhost : test 03:53:52> CREATE TABLE `t1_tmp` (
    ->   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->   `name` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

admin@localhost : test 03:54:34> insert into t1_tmp(id,name) select id,name from t1;

admin@localhost : test 03:56:27> rename table t1 to t1_bak;

admin@localhost : test 03:56:27> rename table t1_bak to t1;

admin@localhost : test 04:00:24> set sql_log_bin=1;  


至此,我们的操作就基本完成了,在另一台master上执行相同之处的操作就OK了。


3.执行此操作的要求

最好能停止业务对数据库的访问,特别是DDL;


4.master的最好结构,

set sql_log_bin=0;的作用和目的:禁止将自己的语句记入二进制日志文件binlog中

当然也就不会更新到备库中;

记得操作完成后,别忘记了执行set sql_log_bin=1;

0 0
原创粉丝点击