1
##################################################################
4
# Purpose: To test changes to mysqlbinlog for row based bin logs #
5
# We are using .opt file since we need small binlog size #
6
##################################################################
8
# Make sure that we have row based bin log
9
-- source include/have_binlog_format_row.inc
10
# Embedded server doesn't support binlogging
11
-- source include/not_embedded.inc
12
-- source include/master-slave.inc
13
# This test requires the cp932 charset compiled in
14
-- source include/have_cp932.inc
17
# we need this for getting fixed timestamps inside of this test
20
select "---Setup Section --" as "";
23
set timestamp=1000000000;
26
DROP TABLE IF EXISTS t1,t2,t3;
30
CREATE TABLE t1(word VARCHAR(20));
31
CREATE TABLE t2(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY);
32
CREATE TABLE t3(c1 INT NOT NULL PRIMARY KEY, c2 LONGBLOB, c3 TIMESTAMP, c4 TEXT, c5 FLOAT);
36
# Lets start by putting some data into the tables.
39
INSERT INTO t1 VALUES ("abirvalg");
40
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
41
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
42
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
43
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
44
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
48
set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1);
49
set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1);
50
set @d1 = concat(@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1,@d1);
55
INSERT INTO t2 VALUES (NULL);
56
eval INSERT INTO t3 VALUES ($count,@d1,'20060222000000','Tested in Texas',$count*2.2);
63
select "---Test1 check table load --" as "";
66
# Lets Check the tables on the Master
67
SELECT COUNT(*) from t1;
68
SELECT COUNT(*) from t2;
69
SELECT COUNT(*) from t3;
70
SELECT * FROM t1 ORDER BY word LIMIT 5;
71
SELECT * FROM t2 ORDER BY id LIMIT 5;
72
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
74
# Should have the same on the slave;
76
sync_slave_with_master;
77
SELECT COUNT(*) from t1;
78
SELECT COUNT(*) from t2;
79
SELECT COUNT(*) from t3;
80
SELECT * FROM t1 ORDER BY word LIMIT 5;
81
SELECT * FROM t2 ORDER BY id LIMIT 5;
82
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
84
# Okay time to get busy, back to master
88
# simple query to show more in second binlog
89
insert into t1 values ("Alas");
92
# delimiters are for easier debugging in future
94
select "--- Test 1 Dump binlog to file --" as "";
98
# Prepare local temporary file to recreate what we have currently.
100
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/master.sql
102
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/master.sql
104
# Now that we have our file, lets get rid of the current database.
105
# Cleanup the master and the slave and try to recreate.
107
select "--- Test 1 delete tables, clean master and slave --" as "";
114
sync_slave_with_master;
115
#we expect STOP SLAVE to produce a warning as the slave is stopped
116
#(the server was started with skip-slave-start)
120
--require r/slave-stopped.result
121
show status like 'Slave_running';
127
--require r/slave-running.result
128
show status like 'Slave_running';
131
# We should be clean at this point, now we will run in the file from above.
133
select "--- Test 1 Load from Dump binlog file --" as "";
136
--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/master.sql"
139
select "--- Test 1 Check Load Results --" as "";
142
# Lets Check the tables on the Master
143
SELECT COUNT(*) from t1;
144
SELECT COUNT(*) from t2;
145
SELECT COUNT(*) from t3;
146
SELECT * FROM t1 ORDER BY word LIMIT 5;
147
SELECT * FROM t2 ORDER BY id LIMIT 5;
148
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
150
# Should have the same on the slave;
152
sync_slave_with_master;
153
SELECT COUNT(*) from t1;
154
SELECT COUNT(*) from t2;
155
SELECT COUNT(*) from t3;
156
SELECT * FROM t1 ORDER BY word LIMIT 5;
157
SELECT * FROM t2 ORDER BY id LIMIT 5;
158
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
161
# We should be gold by the time, so I will get rid of our file.
163
--exec rm $MYSQLTEST_VARDIR/tmp/master.sql
166
# this test for position option
167
# By setting this position to 416, we should only get the create of t3
169
select "--- Test 2 position test --" as "";
171
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
172
--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=417 --stop-position=569 $MYSQLTEST_VARDIR/log/master-bin.000001
174
# These are tests for remote binlog.
175
# They should return the same as previous test.
178
select "--- Test 3 First Remote test --" as "";
182
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
183
--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --stop-position=569 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
185
# This part is disabled due to bug #17654
188
select "--- Test 4 Second Remote test --" as "";
190
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql
192
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/remote.sql
194
# Now that we have our file, lets get rid of the current database.
195
# Cleanup the master and the slave and try to recreate.
201
sync_slave_with_master;
203
#we expect STOP SLAVE to produce a warning as the slave is stopped
204
#(the server was started with skip-slave-start)
209
--require r/slave-stopped.result
210
show status like 'Slave_running';
216
--require r/slave-running.result
217
show status like 'Slave_running';
220
# We should be clean at this point, now we will run in the file from above.
222
--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/remote.sql"
224
# Lets Check the tables on the Master
226
SELECT COUNT(*) from t1;
227
SELECT COUNT(*) from t2;
228
SELECT COUNT(*) from t3;
229
SELECT * FROM t1 ORDER BY word LIMIT 5;
230
SELECT * FROM t2 ORDER BY id LIMIT 5;
231
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
233
# Should have the same on the slave;
235
sync_slave_with_master;
236
SELECT COUNT(*) from t1;
237
SELECT COUNT(*) from t2;
238
SELECT COUNT(*) from t3;
239
SELECT * FROM t1 ORDER BY word LIMIT 5;
240
SELECT * FROM t2 ORDER BY id LIMIT 5;
241
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
244
# We should be gold by the time, so I will get rid of our file.
246
--exec rm $MYSQLTEST_VARDIR/tmp/remote.sql
247
################### End Bug 17654 ######################
249
# What is the point of this test? It seems entirely pointless. It
250
# might make sense for statement-based replication, but for row-based
251
# replication the LOAD DATA INFILE is printed just as empty
252
# transactions. /Matz
256
select "--- Test 5 LOAD DATA --" as "";
258
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
259
--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --stop-position=106 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002
261
# Bug#7853 (mysqlbinlog does not accept input from stdin)
264
select "--- Test 6 reading stdin --" as "";
266
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
267
--exec $MYSQL_BINLOG --short-form --stop-position=569 - < $MYSQLTEST_VARDIR/log/master-bin.000001
270
select "--- Test 7 reading stdin w/position --" as "";
272
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
273
--exec $MYSQL_BINLOG --short-form --position=417 --stop-position=569 - < $MYSQLTEST_VARDIR/log/master-bin.000001
275
# Bug#16217 (mysql client did not know how not switch its internal charset)
277
select "--- Test 8 switch internal charset --" as "";
279
sync_slave_with_master;
281
#we expect STOP SLAVE to produce a warning as the slave is stopped
282
#(the server was started with skip-slave-start)
287
--require r/slave-stopped.result
288
show status like 'Slave_running';
294
--require r/slave-running.result
295
show status like 'Slave_running';
298
create table t4 (f text character set utf8);
299
create table t5 (f text character set cp932);
300
--exec $MYSQL --default-character-set=utf8 test -e "insert into t4 values(_utf8'ソ')"
301
--exec $MYSQL --default-character-set=cp932 test -e "insert into t5 values(_cp932'�\');"
303
rename table t4 to t04, t5 to t05;
304
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 | $MYSQL --default-character-set=utf8
305
# original and recovered data must be equal
306
select HEX(f) from t04;
307
select HEX(f) from t4;
308
select HEX(f) from t05;
309
select HEX(f) from t5;
311
# slave should have same
312
sync_slave_with_master;
313
select HEX(f) from t04;
314
select HEX(f) from t4;
315
select HEX(f) from t05;
316
select HEX(f) from t5;
319
select "--- Test cleanup --" as "";
323
sync_slave_with_master;
327
# BUG#17654 also test mysqlbinlog to ensure it can read the binlog from a remote server
328
# and ensure that the results are the same as if read from a file (the same file).
331
DROP TABLE IF EXISTS t1;
334
CREATE TABLE t1 (a INT NOT NULL KEY, b INT);
336
INSERT INTO t1 VALUES(1,1);
342
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql
343
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/local.sql
345
--diff_files $MYSQLTEST_VARDIR/tmp/local.sql $MYSQLTEST_VARDIR/tmp/remote.sql
347
--exec rm $MYSQLTEST_VARDIR/tmp/remote.sql
349
--exec rm $MYSQLTEST_VARDIR/tmp/local.sql
351
DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5;
352
sync_slave_with_master;