summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author <Dao-Gang.Qu@sun.com>2010-12-29 11:52:57 +0800
committer <Dao-Gang.Qu@sun.com>2010-12-29 11:52:57 +0800
commitdbb832c02e5282e2703e08065f5288aabfebd9ba (patch)
tree0161431412597db7b807408f0051f720a2433b7e
parent920d185fd8551b9737161ee903b2d0bc24dda2f8 (diff)
downloadmariadb-git-dbb832c02e5282e2703e08065f5288aabfebd9ba.tar.gz
Bug #50914 mysqlbinlog not handling drop of current default database
mysqlbinlog only prints "use $database" statements to its output stream when the active default database changes between events. This will cause "No Database Selected" error when dropping and recreating that database. To fix the problem, we clear print_event_info->db when printing an event of CREATE/DROP/ALTER database statements, so that the Query_log_event after such statements will be printed with the use 'db' anyway except transaction keywords.
-rw-r--r--mysql-test/r/mysqlbinlog.result20
-rw-r--r--mysql-test/t/mysqlbinlog.test27
-rw-r--r--sql/log_event.cc7
3 files changed, 53 insertions, 1 deletions
diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result
index 69d19b5e87f..1f2e1ed67e0 100644
--- a/mysql-test/r/mysqlbinlog.result
+++ b/mysql-test/r/mysqlbinlog.result
@@ -638,3 +638,23 @@ ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
End of 5.0 tests
End of 5.1 tests
+RESET MASTER;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+FLUSH LOGS;
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000002 # Query # # CREATE DATABASE test1
+master-bin.000002 # Query # # use `test1`; CREATE TABLE t1(id int)
+master-bin.000002 # Query # # DROP DATABASE test1
+master-bin.000002 # Query # # CREATE DATABASE test1
+master-bin.000002 # Query # # use `test1`; CREATE TABLE t1(id int)
+master-bin.000002 # Query # # use `test1`; DROP TABLE t1
+master-bin.000002 # Query # # DROP DATABASE test1
diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test
index 783708cc3b2..d5dd3052269 100644
--- a/mysql-test/t/mysqlbinlog.test
+++ b/mysql-test/t/mysqlbinlog.test
@@ -474,3 +474,30 @@ diff_files $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn $MYSQLTEST_VARDIR/tmp/mysqlbin
# Cleanup for this part of test
remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn;
+
+#
+# BUG#50914
+# This test verifies if the approach of the mysqlbinlog prints
+# "use $database" statements to its output stream will cause
+# "No Database Selected" error when dropping and recreating
+# that database.
+#
+RESET MASTER;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP DATABASE test1;
+CREATE DATABASE test1;
+USE test1;
+CREATE TABLE t1(id int);
+DROP TABLE t1;
+DROP DATABASE test1;
+let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
+FLUSH LOGS;
+
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+exec $MYSQL_BINLOG $MYSQLD_DATADIR/$master_binlog | $MYSQL test 2>&1;
+
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+source include/show_binlog_events.inc;
+
diff --git a/sql/log_event.cc b/sql/log_event.cc
index eb7c9c30567..0b938df1987 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -2894,7 +2894,12 @@ void Query_log_event::print_query_header(IO_CACHE* file,
error_code);
}
- if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
+ if ((flags & LOG_EVENT_SUPPRESS_USE_F))
+ {
+ if (!is_trans_keyword())
+ print_event_info->db[0]= '\0';
+ }
+ else if (db)
{
different_db= memcmp(print_event_info->db, db, db_len + 1);
if (different_db)