首页 > 数据库技术 > 详细

关于 MySQL sql_log_bin

时间:2021-02-09 22:09:34      阅读:24      评论:0      收藏:0      [点我收藏+]

sql_log_bin表示当前会话是否记录 bin log,默认值on。

打开和关闭sql_log_bin:

SET sql_log_bin = {OFF|ON}

当sql_log_bin关闭后,主库服务器上的改动不记录bin log,不会复制到从库。

全局的sql_log_bin是只读的,不能修改。

如果是基于GTID复制,当关闭sql_log_bin后,任何修改,不会有GTID,也不会记录到bin log。

下面做下测试:

首先查看log file, log pos, 以及 gtid set:

>show master status;
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                                                                                                                                                                          |
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000055 |     1206 |              |                  |a027439b-1d81-11ea-8d1f-002226a4a516:1-118441|
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

接着,关闭sql_log_bin:

>set sql_log_bin=off;
Query OK, 0 rows affected (0.00 sec)

>select @@sql_log_bin;
+---------------+
| @@sql_log_bin |
+---------------+
|             0 |
+---------------+
1 row in set (0.00 sec)

插入新数据:

> insert into xxxxx

再次查看log file, log pos, 以及 gtid set:

>show master status;
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                                                                                                                                                                          |
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000055 |     1206 |              |                  |a027439b-1d81-11ea-8d1f-002226a4a516:1-118441|
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

可以看到,当关闭sql_log_bin后,如果插入新数据,bin log和gtid set都没有变化。

参考

SET sql_log_bin Statement

关于 MySQL sql_log_bin

原文:https://www.cnblogs.com/lanyangsh/p/14393981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!