~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/mysqlbinlog.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_mixed_or_statement.inc
 
4
 
 
5
-- source include/have_log_bin.inc
 
6
 
 
7
# Deletes all the binary logs
 
8
reset master;
 
9
 
 
10
# we need this for getting fixed timestamps inside of this test
 
11
set timestamp=1000000000;
 
12
 
 
13
--disable_warnings
 
14
drop table if exists t1,t2,t3,t4,t5,t03,t04;
 
15
--enable_warnings
 
16
 
 
17
create table t1 (word varchar(20));
 
18
create table t2 (id int auto_increment not null primary key);
 
19
 
 
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);
 
26
 
 
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;
 
37
 
 
38
# delimiters are for easier debugging in future
 
39
--disable_query_log
 
40
select "--- Local --" as "";
 
41
--enable_query_log
 
42
 
 
43
#
 
44
# We should use --short-form everywhere because in other case output will
 
45
# be time dependend. Better than nothing.
 
46
#
 
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
 
51
 
 
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
 
59
 
 
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
 
67
 
 
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
 
75
 
 
76
 
 
77
# These are tests for remote binlog.
 
78
# They should return the same as previous test.
 
79
 
 
80
--disable_query_log
 
81
select "--- Remote --" as "";
 
82
--enable_query_log
 
83
 
 
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
 
88
 
 
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
 
96
 
 
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
 
104
 
 
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
 
112
 
 
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
 
120
 
 
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;
 
125
 
 
126
#
 
127
# Bug#14157 utf8 encoding in binlog without set character_set_client
 
128
#
 
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 `ļæ½ļæ½ļæ½ļæ½ļæ½ļæ½`
 
136
EOF
 
137
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug14157.sql
 
138
--remove_file $MYSQLTEST_VARDIR/tmp/bug14157.sql
 
139
 
 
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;
 
147
 
 
148
#
 
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
 
152
#
 
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;
 
166
 
 
167
#
 
168
# Bug#20396 Bin Log does not get DELIMETER cmd - Recover StoredProc fails
 
169
#
 
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;
 
179
//
 
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;
 
191
 
 
192
#
 
193
# Some coverage of not normally used parts
 
194
#
 
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
 
199
 
 
200
#
 
201
# Bug#15126 character_set_database is not replicated
 
202
# (LOAD DATA INFILE need it)
 
203
#
 
204
 
 
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
 
224
 
 
225
#
 
226
# Bug#28293 missed '#' sign in the hex dump when the dump length
 
227
#           is divisible by 16.
 
228
#
 
229
 
 
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;
 
236
 
 
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
 
241
 
 
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
 
249
 
 
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;
 
256
 
 
257
#
 
258
# Bug#29928 incorrect connection_id() restoring from mysqlbinlog out
 
259
#
 
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;
 
278
 
 
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
 
283
 
 
284
 
 
285
#
 
286
# Test --disable-force-if-open and --force-if-open
 
287
#
 
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
 
292
 
 
293
--echo Bug#31611 Security risk with BINLOG statement
 
294
 
 
295
SET BINLOG_FORMAT=ROW;
 
296
CREATE DATABASE mysqltest1;
 
297
CREATE USER untrusted@localhost;
 
298
GRANT SELECT ON mysqltest1.* TO untrusted@localhost;
 
299
 
 
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());
 
316
 
 
317
SELECT * FROM t1;
 
318
connection default;
 
319
DROP DATABASE mysqltest1;
 
320
DROP USER untrusted@localhost;
 
321
 
 
322
--echo Bug#32580 mysqlbinlog cannot read binlog event with user variables
 
323
 
 
324
# Testing that various kinds of events can be read and restored properly.
 
325
 
 
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;
 
339
 
 
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;
 
345
 
 
346
query_vertical SELECT * FROM t1;
 
347
DROP TABLE t1;
 
348
 
 
349
#
 
350
# Bug#37313 BINLOG Contains Incorrect server id
 
351
#
 
352
 
 
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;
 
357
 
 
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 ***;
 
367
 
 
368
eval SET @@global.server_id= $save_server_id;
 
369
--remove_file $binlog_file
 
370
 
 
371
#
 
372
# Bug #41943: mysqlbinlog.exe crashes if --hexdump option is used
 
373
#
 
374
 
 
375
RESET MASTER;
 
376
FLUSH LOGS;
 
377
 
 
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
 
380
 
 
381
#
 
382
# #46998
 
383
# This test verifies if the 'BEGIN', 'COMMIT' and 'ROLLBACK' are output 
 
384
# in regardless of database filtering
 
385
#
 
386
 
 
387
RESET MASTER;
 
388
FLUSH LOGS;
 
389
 
 
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
 
405
 
 
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
 
420
 
 
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
 
435
 
 
436
--echo #
 
437
--echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified is exist
 
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 is not exist
 
441
--exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001
 
442
 
 
443
--echo End of 5.0 tests
 
444
 
 
445
--echo End of 5.1 tests