Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug#67433: Using SET GLOBAL SQL_LOG_BIN should not be allowed

Earlier in MySQL 5.5 development cycle, the SQL_LOG_BIN variable was
made to be both global and session-scoped, instead of only session as
it was in previous releases. The problem is that usage of SQL_LOG_BIN
at the global scope can be quite dangerous.

When SQL_LOG_BIN is changed globally, it does not immediately take
effect for any sessions. It takes effect by becoming the default value
for new sessions, and this setting is kept and cached for the duration
of that session (unless changed). Setting it intentionally is unlikely
to have a useful effect under any circumstance; setting it
unintentionally, such as while intending to use SET [SESSION] is
potentially disastrous.

Accidentally using SET GLOBAL SQL_LOG_BIN will not show an immediate
effect to the user, it won't have the desired session-level effect,
and might cause other potential problems with local-only maintenance
being logged and executed on slaves. Furthermore, a bigger problem is
with the long term and possibly permanent damage which may result in
irrecoverable or difficult data loss with binary logging being
disabled for new (and unrelated) sessions.

The solution is to revert the change and again make SQL_LOG_BIN a
session-only variable, generating an error if it is used with SET
GLOBAL.
  • Loading branch information...
commit 9302f22d9da38558908f0e2c8ae24af75c0b8a8b 1 parent dec51ac
Davi Arnaut authored
View
8 mysql-test/suite/binlog/r/binlog_switch_inside_trans.result
@@ -1,6 +1,5 @@
set @save_binlog_format= @@global.binlog_format;
set @save_binlog_dirct= @@global.binlog_direct_non_transactional_updates;
-set @save_sql_log_bin= @@global.sql_log_bin;
create table t1 (a int) engine= myisam;
create table t2 (a int) engine= innodb;
SELECT @@session.binlog_format;
@@ -129,7 +128,7 @@ commit;
begin;
insert into t2 values (5);
# Test that the global variable 'binlog_format' and
-# 'binlog_direct_non_transactional_updates' and 'sql_log_bin' are
+# 'binlog_direct_non_transactional_updates' are
# writable inside a transaction.
# Current session values are ROW, FALSE, TRUE respectively.
SELECT @@global.binlog_format;
@@ -137,20 +136,15 @@ SELECT @@global.binlog_format;
ROW
set @@global.binlog_format= statement;
set @@global.binlog_direct_non_transactional_updates= TRUE;
-set @@global.sql_log_bin= FALSE;
SELECT @@global.binlog_format;
@@global.binlog_format
STATEMENT
SELECT @@global.binlog_direct_non_transactional_updates;
@@global.binlog_direct_non_transactional_updates
1
-SELECT @@global.sql_log_bin;
-@@global.sql_log_bin
-0
commit;
set @@global.binlog_format= @save_binlog_format;
set @@global.binlog_direct_non_transactional_updates= @save_binlog_dirct;
-set @@global.sql_log_bin= @save_sql_log_bin;
create table t3(a int, b int) engine= innodb;
create table t4(a int) engine= innodb;
create table t5(a int) engine= innodb;
View
3  mysql-test/suite/binlog/t/binlog_grant.test
@@ -15,8 +15,7 @@ show grants for mysqltest_1@localhost;
connect (plain,localhost,mysqltest_1,,test);
connect (root,localhost,root,,test);
-# Testing setting both session and global SQL_LOG_BIN variable both as
-# root and as plain user.
+# Testing setting SQL_LOG_BIN variable both as root and as plain user.
--echo **** Variable SQL_LOG_BIN ****
View
6 mysql-test/suite/binlog/t/binlog_switch_inside_trans.test
@@ -10,7 +10,6 @@ source include/have_binlog_format_row.inc;
set @save_binlog_format= @@global.binlog_format;
set @save_binlog_dirct= @@global.binlog_direct_non_transactional_updates;
-set @save_sql_log_bin= @@global.sql_log_bin;
create table t1 (a int) engine= myisam;
create table t2 (a int) engine= innodb;
@@ -117,21 +116,18 @@ commit;
begin;
insert into t2 values (5);
--echo # Test that the global variable 'binlog_format' and
---echo # 'binlog_direct_non_transactional_updates' and 'sql_log_bin' are
+--echo # 'binlog_direct_non_transactional_updates' are
--echo # writable inside a transaction.
--echo # Current session values are ROW, FALSE, TRUE respectively.
SELECT @@global.binlog_format;
set @@global.binlog_format= statement;
set @@global.binlog_direct_non_transactional_updates= TRUE;
- set @@global.sql_log_bin= FALSE;
SELECT @@global.binlog_format;
SELECT @@global.binlog_direct_non_transactional_updates;
- SELECT @@global.sql_log_bin;
commit;
set @@global.binlog_format= @save_binlog_format;
set @@global.binlog_direct_non_transactional_updates= @save_binlog_dirct;
-set @@global.sql_log_bin= @save_sql_log_bin;
create table t3(a int, b int) engine= innodb;
create table t4(a int) engine= innodb;
View
7 mysql-test/suite/sys_vars/r/sql_log_bin_basic.result
@@ -58,14 +58,13 @@ SET @@session.sql_log_bin = NO;
ERROR 42000: Variable 'sql_log_bin' can't be set to the value of 'NO'
'#-------------------FN_DYNVARS_156_05----------------------------#'
SET @@global.sql_log_bin = 0;
+ERROR HY000: Variable 'sql_log_bin' is a SESSION variable and can't be used with SET GLOBAL
SELECT @@global.sql_log_bin;
-@@global.sql_log_bin
-0
-SET @@global.sql_log_bin = 1;
+ERROR HY000: Variable 'sql_log_bin' is a SESSION variable
'#----------------------FN_DYNVARS_156_06------------------------#'
SELECT count(VARIABLE_VALUE) FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='sql_log_bin';
count(VARIABLE_VALUE)
-1
+0
'#----------------------FN_DYNVARS_156_07------------------------#'
SELECT IF(@@session.sql_log_bin, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
View
4 mysql-test/suite/sys_vars/t/sql_log_bin_basic.test
@@ -112,9 +112,11 @@ SET @@session.sql_log_bin = NO;
# Test if accessing global sql_log_bin gives error #
###########################################################################
+--Error ER_LOCAL_VARIABLE
SET @@global.sql_log_bin = 0;
+
+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT @@global.sql_log_bin;
-SET @@global.sql_log_bin = 1;
--echo '#----------------------FN_DYNVARS_156_06------------------------#'
#########################################################################
View
18 sql/sys_vars.cc
@@ -2502,13 +2502,13 @@ static Sys_var_bit Sys_log_off(
static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd,
enum_var_type type)
{
- if (type == OPT_SESSION)
- {
- if (thd->variables.sql_log_bin)
- thd->variables.option_bits |= OPTION_BIN_LOG;
- else
- thd->variables.option_bits &= ~OPTION_BIN_LOG;
- }
+ DBUG_ASSERT(type == OPT_SESSION);
+
+ if (thd->variables.sql_log_bin)
+ thd->variables.option_bits |= OPTION_BIN_LOG;
+ else
+ thd->variables.option_bits &= ~OPTION_BIN_LOG;
+
return FALSE;
}
@@ -2549,8 +2549,8 @@ static bool check_sql_log_bin(sys_var *self, THD *thd, set_var *var)
}
static Sys_var_mybool Sys_log_binlog(
- "sql_log_bin", "sql_log_bin",
- SESSION_VAR(sql_log_bin), NO_CMD_LINE,
+ "sql_log_bin", "Controls whether logging to the binary log is done",
+ SESSION_ONLY(sql_log_bin), NO_CMD_LINE,
DEFAULT(TRUE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_sql_log_bin),
ON_UPDATE(fix_sql_log_bin_after_update));
Please sign in to comment.
Something went wrong with that request. Please try again.