mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / mysqlbinlog.test
blob98ee18b554e0f792f70f5d8677c9b608711f23b8
1 # We are using .opt file since we need small binlog size
2 # TODO: Need to look at making a row based version once the new row based client is completed. [jbm]
3 -- source include/have_binlog_format_statement.inc
5 -- source include/have_log_bin.inc
7 # Deletes all the binary logs
8 reset master;
10 # we need this for getting fixed timestamps inside of this test
11 set timestamp=1000000000;
13 --disable_warnings
14 drop table if exists t1,t2,t3,t4,t5,t03,t04;
15 --enable_warnings
17 create table t1 (word varchar(20));
18 create table t2 (id int auto_increment not null primary key);
20 # simple test for simple statement and various events
21 insert into t1 values ("abirvalg");
22 insert into t2 values ();
23 # Should be uncommented in 4.1
24 # set @a:=1
25 # insert into t2 values (@a);
27 # test for load data and load data distributed among the several
28 # files (we need to fill up first binlog)
29 load data infile '../../std_data/words.dat' into table t1;
30 load data infile '../../std_data/words.dat' into table t1;
31 load data infile '../../std_data/words.dat' into table t1;
32 load data infile '../../std_data/words.dat' into table t1;
33 load data infile '../../std_data/words.dat' into table t1;
34 # simple query to show more in second binlog
35 insert into t1 values ("Alas");
36 flush logs;
38 # delimiters are for easier debugging in future
39 --disable_query_log
40 select "--- Local --" as "";
41 --enable_query_log
44 # We should use --short-form everywhere because in other case output will
45 # be time dependend. Better than nothing.
47 let $MYSQLD_DATADIR= `select @@datadir`;
48 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
49 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
50 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000001
52 # this should not fail but shouldn't produce any working statements
53 --disable_query_log
54 select "--- Broken LOAD DATA --" as "";
55 --enable_query_log
56 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
57 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
58 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000002 2> /dev/null
60 # this should show almost nothing
61 --disable_query_log
62 select "--- --database --" as "";
63 --enable_query_log
64 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
65 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
66 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --database=nottest $MYSQLD_DATADIR/master-bin.000001 2> /dev/null
68 # this test for position option
69 --disable_query_log
70 select "--- --position --" as "";
71 --enable_query_log
72 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
73 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
74 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=332 $MYSQLD_DATADIR/master-bin.000002
77 # These are tests for remote binlog.
78 # They should return the same as previous test.
80 --disable_query_log
81 select "--- Remote --" as "";
82 --enable_query_log
84 # This is broken now
85 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
86 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
87 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
89 # This is broken too
90 --disable_query_log
91 select "--- Broken LOAD DATA --" as "";
92 --enable_query_log
93 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
94 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
95 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 2> /dev/null
97 # And this too ! (altough it is documented)
98 --disable_query_log
99 select "--- --database --" as "";
100 --enable_query_log
101 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
102 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
103 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --database=nottest master-bin.000001 2> /dev/null
105 # Strangely but this works
106 --disable_query_log
107 select "--- --position --" as "";
108 --enable_query_log
109 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
110 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
111 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --position=332 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002
113 # Bug#7853 mysqlbinlog does not accept input from stdin
114 --disable_query_log
115 select "--- reading stdin --" as "";
116 --enable_query_log
117 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
118 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
119 --exec $MYSQL_BINLOG --short-form - < $MYSQL_TEST_DIR/std_data/trunc_binlog.000001
121 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
122 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
123 --exec $MYSQL_BINLOG --short-form --position=79 - < $MYSQL_TEST_DIR/std_data/trunc_binlog.000001
124 drop table t1,t2;
127 # Bug#14157 utf8 encoding in binlog without set character_set_client
129 flush logs;
130 --write_file $MYSQLTEST_VARDIR/tmp/bug14157.sql
131 create table if not exists t5 (a int);
132 set names latin1;
133 create temporary table `äöüÄÖÜ` (a int);
134 insert into `äöüÄÖÜ` values (1);
135 insert into t5 select * from `äöüÄÖÜ`
137 --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug14157.sql
138 --remove_file $MYSQLTEST_VARDIR/tmp/bug14157.sql
140 # resulted binlog, parly consisting of multi-byte utf8 chars,
141 # must be digestable for both client and server. In 4.1 the client
142 # should use default-character-set same as the server.
143 flush logs;
144 --exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000004 | $MYSQL
145 select * from t5  /* must be (1),(1) */;
146 drop table t5;
149 # Bug#22645 LC_TIME_NAMES: Statement not replicated
150 # Check that a dump created by mysqlbinlog reproduces
151 # lc_time_names dependent values correctly
153 flush logs;
154 create table t5 (c1 int, c2 varchar(128) character set latin1 not null);
155 insert into t5 values (1, date_format('2001-01-01','%W'));
156 set lc_time_names=de_DE;
157 insert into t5 values (2, date_format('2001-01-01','%W'));
158 set lc_time_names=en_US;
159 insert into t5 values (3, date_format('2001-01-01','%W'));
160 select * from t5 order by c1;
161 flush logs;
162 drop table t5;
163 --exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000006 | $MYSQL
164 select * from t5 order by c1;
165 drop table t5;
168 # Bug#20396 Bin Log does not get DELIMETER cmd - Recover StoredProc fails
170 --disable_warnings
171 drop procedure if exists p1;
172 --enable_warnings
173 flush logs;
174 delimiter //;
175 create procedure p1()
176 begin
177 select 1;
178 end;
180 delimiter ;//
181 flush logs;
182 call p1();
183 drop procedure p1;
184 --error ER_SP_DOES_NOT_EXIST
185 call p1();
186 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
187 --exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000008
188 --exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000008 | $MYSQL
189 call p1();
190 drop procedure p1;
193 # Some coverage of not normally used parts
195 --disable_query_log
196 --exec $MYSQL_BINLOG --version 2>&1 > /dev/null
197 --exec $MYSQL_BINLOG --help 2>&1 > /dev/null
198 --enable_query_log
201 # Bug#15126 character_set_database is not replicated
202 # (LOAD DATA INFILE need it)
205 flush logs;
206 create table t1 (a varchar(64) character set utf8);
207 load data infile '../../std_data/loaddata6.dat' into table t1;
208 set character_set_database=koi8r;
209 load data infile '../../std_data/loaddata6.dat' into table t1;
210 set character_set_database=latin1;
211 load data infile '../../std_data/loaddata6.dat' into table t1;
212 load data infile '../../std_data/loaddata6.dat' into table t1;
213 set character_set_database=koi8r;
214 load data infile '../../std_data/loaddata6.dat' into table t1;
215 set character_set_database=latin1;
216 load data infile '../../std_data/loaddata6.dat' into table t1;
217 load data infile '../../std_data/loaddata6.dat' into table t1 character set koi8r;
218 select hex(a) from t1;
219 drop table t1;
220 flush logs;
221 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
222 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
223 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000010
226 # Bug#28293 missed '#' sign in the hex dump when the dump length
227 #           is divisible by 16.
230 CREATE TABLE t1 (c1 CHAR(10));
231 # we need this for getting fixed timestamps inside of this test
232 FLUSH LOGS;
233 INSERT INTO t1 VALUES ('0123456789');
234 FLUSH LOGS;
235 DROP TABLE t1;
237 # We create a table, patch, and load the output into it
238 # By using LINES STARTING BY '#' + SELECT WHERE a LIKE 'Query'
239 # We can easily see if a 'Query' line is missing the '#' character
240 # as described in the original bug
242 --disable_query_log
243 CREATE TABLE patch (a BLOB);
244 --exec $MYSQL_BINLOG --hexdump --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000012 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat
245 eval LOAD DATA LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat'
246      INTO TABLE patch FIELDS TERMINATED BY '' LINES STARTING BY '#';
247 --remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat
248 --enable_query_log
250 --echo We expect this value to be 1
251 --echo The bug being tested was that 'Query' lines were not preceded by '#'
252 --echo If the line is in the table, it had to have been preceded by a '#'
253 --echo
254 SELECT COUNT(*) AS `BUG#28293_expect_1` FROM patch WHERE a LIKE '%Query%';
255 DROP TABLE patch;
258 # Bug#29928 incorrect connection_id() restoring from mysqlbinlog out
260 FLUSH LOGS;
261 CREATE TABLE t1(a INT);
262 INSERT INTO t1 VALUES(connection_id());
263 let $a= `SELECT a FROM t1`;
264 FLUSH LOGS;
265 let $outfile= $MYSQLTEST_VARDIR/tmp/bug29928.sql;
266 --exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000014 > $outfile
267 DROP TABLE t1;
268 connect (con1, localhost, root, , test);
269 connection con1;
270 --exec $MYSQL test < $outfile
271 --remove_file $outfile
272 let $b= `SELECT a FROM t1`;
273 disconnect con1;
274 connection default;
275 let $c= `SELECT $a=$b`;
276 --echo $c
277 DROP TABLE t1;
279 echo shell> mysqlbinlog std_data/corrupt-relay-bin.000624 > var/tmp/bug31793.sql;
280 error 1;
281 exec $MYSQL_BINLOG $MYSQL_TEST_DIR/std_data/corrupt-relay-bin.000624 > $MYSQLTEST_VARDIR/tmp/bug31793.sql;
282 --remove_file $MYSQLTEST_VARDIR/tmp/bug31793.sql
286 # Test --disable-force-if-open and --force-if-open
288 FLUSH LOGS;
289 --error 1
290 --exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000016 >/dev/null 2>/dev/null
291 --exec $MYSQL_BINLOG --force-if-open $MYSQLD_DATADIR/master-bin.000016 >/dev/null 2>/dev/null
293 --echo Bug#31611 Security risk with BINLOG statement
295 SET BINLOG_FORMAT=ROW;
296 CREATE DATABASE mysqltest1;
297 CREATE USER untrusted@localhost;
298 GRANT SELECT ON mysqltest1.* TO untrusted@localhost;
300 SHOW GRANTS FOR untrusted@localhost;
301 USE mysqltest1;
302 CREATE TABLE t1 (a INT, b CHAR(64));
303 flush logs;
304 INSERT INTO t1 VALUES (1,USER());
305 flush logs;
306 echo mysqlbinlog var/log/master-bin.000017 > var/tmp/bug31611.sql;
307 exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000017 > $MYSQLTEST_VARDIR/tmp/bug31611.sql;
308 connect (unsecure,localhost,untrusted,,mysqltest1);
309 echo mysql mysqltest1 -uuntrusted < var/tmp/bug31611.sql;
310 error 1;
311 exec $MYSQL mysqltest1 -uuntrusted < $MYSQLTEST_VARDIR/tmp/bug31611.sql;
312 --remove_file $MYSQLTEST_VARDIR/tmp/bug31611.sql
313 connection unsecure;
314 error ER_TABLEACCESS_DENIED_ERROR;
315 INSERT INTO t1 VALUES (1,USER());
317 SELECT * FROM t1;
318 connection default;
319 DROP DATABASE mysqltest1;
320 DROP USER untrusted@localhost;
322 --echo Bug#32580 mysqlbinlog cannot read binlog event with user variables
324 # Testing that various kinds of events can be read and restored properly.
326 connection default;
327 USE test;
328 SET BINLOG_FORMAT = STATEMENT;
329 FLUSH LOGS;
330 CREATE TABLE t1 (a_real FLOAT, an_int INT, a_decimal DECIMAL(5,2), a_string CHAR(32));
331 SET @a_real = rand(20) * 1000;
332 SET @an_int = 1000;
333 SET @a_decimal = CAST(rand(19) * 999 AS DECIMAL(5,2));
334 SET @a_string = 'Just a test';
335 INSERT INTO t1 VALUES (@a_real, @an_int, @a_decimal, @a_string);
336 FLUSH LOGS;
337 query_vertical SELECT * FROM t1;
338 DROP TABLE t1;
340 echo >> mysqlbinlog var/log/master-bin.000019 > var/tmp/bug32580.sql;
341 exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000019 > $MYSQLTEST_VARDIR/tmp/bug32580.sql;
342 echo >> mysql test < var/tmp/bug32580.sql;
343 exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug32580.sql;
344 remove_file $MYSQLTEST_VARDIR/tmp/bug32580.sql;
346 query_vertical SELECT * FROM t1;
347 DROP TABLE t1;
350 # Bug#37313 BINLOG Contains Incorrect server id
353 let $binlog_file=  $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug37313.binlog;
354 let $save_server_id= `SELECT @@global.server_id`;
355 let $s_id_max= `SELECT (1 << 32) - 1`;
356 eval SET @@global.server_id= $s_id_max;
358 RESET MASTER;
359 FLUSH LOGS;
360 --exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $binlog_file
361 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
362 eval SELECT
363 (@a:=LOAD_FILE("$binlog_file"))
364 IS NOT NULL;
365 let $s_id_unsigned= `SELECT @a LIKE "%server id $s_id_max%" /* must return 1 */`;
366 echo *** Unsigned server_id $s_id_max is found: $s_id_unsigned ***;
368 eval SET @@global.server_id= $save_server_id;
369 --remove_file $binlog_file
372 # Bug #41943: mysqlbinlog.exe crashes if --hexdump option is used
375 RESET MASTER;
376 FLUSH LOGS;
378 # We do not need the results, just make sure that mysqlbinlog does not crash
379 --exec $MYSQL_BINLOG --hexdump --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT  master-bin.000001 >/dev/null
382 # #46998
383 # This test verifies if the 'BEGIN', 'COMMIT' and 'ROLLBACK' are output 
384 # in regardless of database filtering
387 RESET MASTER;
388 FLUSH LOGS;
390 # The following three test cases were wrtten into binlog_transaction.000001
391 # Test case1: Test if the 'BEGIN' and 'COMMIT' are output for the 'test' database 
392 # in transaction1 base on innodb engine tables
393 # use test;
394 # create table t1(a int) engine= innodb;
395 # use mysql;
396 # create table t2(a int) engine= innodb;
397 # Transaction1 begin
398 # begin;
399 # use test;
400 # insert into t1 (a) values (1);
401 # use mysql;
402 # insert into t2 (a) values (1);
403 # commit;
404 # Transaction1 end
406 # Test case2: Test if the 'BEGIN' and 'ROLLBACK' are output for the 'test' database 
407 # in transaction2 base on innodb and myisam engine tables
408 # use test;
409 # create table t3(a int) engine= innodb;
410 # use mysql;
411 # create table t4(a int) engine= myisam;
412 # Transaction2 begin
413 # begin;
414 # use test;
415 # insert into t3 (a) values (2);
416 # use mysql;
417 # insert into t4 (a) values (2);
418 # rollback;
419 # Transaction2 end
421 # Test case3: Test if the 'BEGIN' and 'COMMIT' are output for the 'test' database 
422 # in transaction3 base on NDB engine tables
423 # use test;
424 # create table t5(a int) engine= NDB;
425 # use mysql;
426 # create table t6(a int) engine= NDB;
427 # Transaction3 begin
428 # begin;
429 # use test;
430 # insert into t5 (a) values (3);
431 # use mysql;
432 # insert into t6 (a) values (3);
433 # commit;
434 # Transaction3 end
436 --echo #
437 --echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified exists
438 --exec $MYSQL_BINLOG --database=test --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001
439 --echo #
440 --echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified does not exist
441 --exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001
443 --echo #
444 --echo # Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified exists
445 --exec $MYSQL_BINLOG --database=db1 --short-form $MYSQLTEST_VARDIR/std_data/binlog_savepoint.000001
446 --echo #
447 --echo # Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified does not exist
448 --exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_savepoint.000001
450 --echo End of 5.0 tests
452 --echo End of 5.1 tests
455 # BUG#38468 Memory leak detected when using mysqlbinlog utility;
457 disable_query_log;
458 RESET MASTER;
459 CREATE TABLE t1 SELECT 1;
460 FLUSH LOGS;
461 DROP TABLE t1;
462 enable_query_log;
464 # Write an empty file for comparison
465 write_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
468 # Before fix of BUG#38468, this would generate some warnings
469 --exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 >/dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn
471 # Make sure the command above does not generate any error or warnings
472 diff_files $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
474 # Cleanup for this part of test
475 remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
476 remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn;
479 # BUG#50914
480 # This test verifies if the approach of the mysqlbinlog prints
481 # "use $database" statements to its output stream will cause
482 # "No Database Selected" error when dropping and recreating
483 # that database.
485 RESET MASTER;
486 CREATE DATABASE test1;
487 USE test1;
488 CREATE TABLE t1(id int);
489 DROP DATABASE test1;
490 CREATE DATABASE test1;
491 USE test1;
492 CREATE TABLE t1(id int);
493 DROP TABLE t1;
494 DROP DATABASE test1;
495 let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
496 FLUSH LOGS;
498 let $MYSQLD_DATADIR= `SELECT @@datadir`;
499 exec $MYSQL_BINLOG $MYSQLD_DATADIR/$master_binlog | $MYSQL test 2>&1;
501 let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
502 source include/show_binlog_events.inc;
505 # BUG#11766427 BUG#59530: Filter by server id in mysqlbinlog fails
506 # This test checks that the format description log event is not
507 # filtered out by the --server-id option.
509 RESET MASTER;
510 USE test;
511 CREATE TABLE t1 (a INT);
512 --let $old_server_id= `SELECT @@GLOBAL.SERVER_ID`
513 SET GLOBAL SERVER_ID = 2;
514 DROP TABLE t1;
515 --let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
516 FLUSH LOGS;
517 # The following should only create t1, not drop it.
518 --exec $MYSQL_BINLOG --server-id=1 $MYSQLD_DATADIR/$master_binlog | $MYSQL
519 SHOW TABLES IN test;
520 # The following should only drop t1, not create it.
521 --exec $MYSQL_BINLOG --server-id=2 $MYSQLD_DATADIR/$master_binlog | $MYSQL
522 SHOW TABLES IN test;
523 eval SET GLOBAL SERVER_ID = $old_server_id;