diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index ce83fe5b79b..0b9f6db05b8 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -883,3 +883,23 @@ End of 5.1 tests WARNING: The --base64-output=always flag and the --base64-output flag (with '=MODE' omitted), are deprecated. The output generated when these flags are used cannot be parsed by mysql 5.6.0 and later. The flags will be removed in a future version. Please use --base64-output=auto instead. # Expect deprecation warning again. WARNING: The --base64-output=always flag and the --base64-output flag (with '=MODE' omitted), are deprecated. The output generated when these flags are used cannot be parsed by mysql 5.6.0 and later. The flags will be removed in a future version. Please use --base64-output=auto instead. +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 ; +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` /* generated by server */ +master-bin.000002 # Query # # DROP DATABASE test1 diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index 76f6c63fc1d..714cfbbaa9b 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -491,7 +491,6 @@ remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn; # # WL#5625: Deprecate mysqlbinlog options --base64-output=always and --base64-output # - --echo # Expect deprecation warning. --exec $MYSQL_BINLOG --base64-output=always std_data/master-bin.000001 > /dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn --cat_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn @@ -502,3 +501,29 @@ remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn; # Clean up this part of the test. --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 916a95e170f..b9da915ba96 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2969,7 +2969,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)