| 1 |
|
| 2 |
######################################################## |
| 3 |
# Test mysqlbinlog command with Ndb produced Binlog |
| 4 |
# variants |
| 5 |
# |
| 6 |
# WHAT |
| 7 |
# ==== |
| 8 |
# This test aims to check that the mysqlbinlog --verbose |
| 9 |
# command can output binlogs in 4 format variants, currently |
| 10 |
# used by Ndb |
| 11 |
# |
| 12 |
# 1) Updates logged as write_row events |
| 13 |
# Only primary key and updated columns included in the |
| 14 |
# event |
| 15 |
# 2) Updates logged as write_row_events |
| 16 |
# All columns included in the event |
| 17 |
# 3) Updates logged as update_row events |
| 18 |
# Only primary key and updated columns included in the |
| 19 |
# event |
| 20 |
# 4) Updates logged as update_row events |
| 21 |
# All columns included in the event |
| 22 |
# |
| 23 |
# Format variant (1) is the Ndb default. |
| 24 |
# Bug#47323 resulted in binlogs generated in format (1) |
| 25 |
# being incorrectly parsed by the mysqlbinlog --verbose |
| 26 |
# option |
| 27 |
# |
| 28 |
# HOW |
| 29 |
# === |
| 30 |
# Row-based binlog files in each format have been |
| 31 |
# captured from an Ndb cluster |
| 32 |
# These are output using the mysqlbinlog --verbose |
| 33 |
# tool and the output is checked. |
| 34 |
# |
| 35 |
######################################################## |
| 36 |
-- source include/have_binlog_format_row.inc |
| 37 |
|
| 38 |
--disable_query_log |
| 39 |
--let $binlog_file=write-partial-row.binlog |
| 40 |
--exec $MYSQL_BINLOG --verbose suite/binlog/std_data/$binlog_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 41 |
create table raw_binlog_rows (txt varchar(1000)); |
| 42 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql' into table raw_binlog_rows columns terminated by '\n'; |
| 43 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 44 |
--enable_query_log |
| 45 |
--echo Verbose statements from : $binlog_file |
| 46 |
# Output --verbose lines, with extra Windows CR's trimmed |
| 47 |
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; |
| 48 |
drop table raw_binlog_rows; |
| 49 |
|
| 50 |
--disable_query_log |
| 51 |
--let $binlog_file=write-full-row.binlog |
| 52 |
--exec $MYSQL_BINLOG --verbose suite/binlog/std_data/$binlog_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 53 |
create table raw_binlog_rows (txt varchar(1000)); |
| 54 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql' into table raw_binlog_rows columns terminated by '\n'; |
| 55 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 56 |
--enable_query_log |
| 57 |
--echo Verbose statements from : $binlog_file |
| 58 |
# Output --verbose lines, with extra Windows CR's trimmed |
| 59 |
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; |
| 60 |
drop table raw_binlog_rows; |
| 61 |
|
| 62 |
--disable_query_log |
| 63 |
--let $binlog_file=update-partial-row.binlog |
| 64 |
--exec $MYSQL_BINLOG --verbose suite/binlog/std_data/$binlog_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 65 |
create table raw_binlog_rows (txt varchar(1000)); |
| 66 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql' into table raw_binlog_rows columns terminated by '\n'; |
| 67 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 68 |
--enable_query_log |
| 69 |
--echo Verbose statements from : $binlog_file |
| 70 |
# Output --verbose lines, with extra Windows CR's trimmed |
| 71 |
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; |
| 72 |
drop table raw_binlog_rows; |
| 73 |
|
| 74 |
--disable_query_log |
| 75 |
--let $binlog_file=update-full-row.binlog |
| 76 |
--exec $MYSQL_BINLOG --verbose suite/binlog/std_data/$binlog_file > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 77 |
create table raw_binlog_rows (txt varchar(1000)); |
| 78 |
--eval load data local infile '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql' into table raw_binlog_rows columns terminated by '\n'; |
| 79 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_verbose.sql |
| 80 |
--enable_query_log |
| 81 |
--echo Verbose statements from : $binlog_file |
| 82 |
# Output --verbose lines, with extra Windows CR's trimmed |
| 83 |
select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%'; |
| 84 |
drop table raw_binlog_rows; |
| 85 |
|
| 86 |
|
| 87 |
####################################################################### |
| 88 |
# BUG#13799555: ROWS_QUERY_LOG_EVENTS DOES NOT ESCAPE MULTI-LINE QUERIES PROPERLY |
| 89 |
# |
| 90 |
# Check that when mysqlbinlog is given the option --verbose --verbose, |
| 91 |
# the multi-line original statement are properly escaped to prevent from |
| 92 |
# being executed. |
| 93 |
SET @@SESSION.BINLOG_ROWS_QUERY_LOG_EVENTS = 1; |
| 94 |
CREATE TABLE t1 (a VARCHAR(50)); |
| 95 |
--let $binlog_start_position= query_get_value("SHOW MASTER STATUS", Position, 1) |
| 96 |
|
| 97 |
--delimiter | |
| 98 |
INSERT INTO t1 VALUES (" |
| 99 |
GRANT ALL ON *.* TO 'batman'/*!*/; |
| 100 |
")| |
| 101 |
--delimiter ; |
| 102 |
|
| 103 |
DROP TABLE t1; |
| 104 |
|
| 105 |
--let $binlog_stop_position= query_get_value("SHOW MASTER STATUS", Position, 1) |
| 106 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 107 |
--let $datadir= `SELECT @@datadir` |
| 108 |
|
| 109 |
--let $_prefix= `SELECT UUID()` |
| 110 |
--let $TMP_FILE= $MYSQLTEST_VARDIR/tmp/$_prefix.tmp |
| 111 |
--exec $MYSQL_BINLOG --force-if-open --verbose --verbose --start-position=$binlog_start_position --stop-position=$binlog_stop_position $datadir/$binlog_file > $TMP_FILE |
| 112 |
|
| 113 |
--let TMP_FILE= $TMP_FILE |
| 114 |
--perl END_OF_FILE |
| 115 |
my $tmp_file= $ENV{'TMP_FILE'}; |
| 116 |
|
| 117 |
my $escaped_query = <<END; |
| 118 |
# INSERT INTO t1 VALUES (" |
| 119 |
# GRANT ALL ON *.* TO 'batman'/*!*/; |
| 120 |
# ") |
| 121 |
END |
| 122 |
|
| 123 |
open(FILE, $tmp_file) or die("Unable to open $tmp_file: $!\n"); |
| 124 |
my $contents = do { local $/; <FILE> }; |
| 125 |
close(FILE) or die("Unable to close file."); |
| 126 |
|
| 127 |
$match= index($contents, $escaped_query) > -1; |
| 128 |
if (!$match) |
| 129 |
{ |
| 130 |
print "\n====================================================\n"; |
| 131 |
print "ESCAPED STRING DID NOT MATCH:\n"; |
| 132 |
print "====================================================\n"; |
| 133 |
print "$escaped_query"; |
| 134 |
print "====================================================\n"; |
| 135 |
|
| 136 |
print "\n====================================================\n"; |
| 137 |
print "BINLOG CONTENTS\n"; |
| 138 |
print "====================================================\n"; |
| 139 |
print "$contents"; |
| 140 |
print "====================================================\n"; |
| 141 |
} |
| 142 |
END_OF_FILE |
| 143 |
|
| 144 |
# Clean up |
| 145 |
--remove_file $TMP_FILE |