File: import.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (673 lines) | stat: -rw-r--r-- 20,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#Test requires MyISAM SE 
--source include/force_myisam_default.inc
--source include/have_myisam.inc

--echo #
--echo # Testing WL#7524 - Import from SDI files
--echo #

--echo # Setup test environment
let $MYSQLD_DATADIR=`SELECT @@datadir`;
--perl
chdir $ENV{'MYSQL_TMP_DIR'};
mkdir "export";
EOF
let $EXPORT_DIR= $MYSQL_TMP_DIR/export;


--echo #
--echo # IM-NEG-1: Schema missing/wrong schema name in SDI
--echo #
CREATE SCHEMA s1;
CREATE TABLE s1.t1(i VARCHAR(32)) ENGINE MYISAM;
INSERT INTO s1.t1 VALUES ('abc'), ('DEF'), ('Ghi'), ('ghI');
SELECT I FROM s1.t1 ORDER BY i;

FLUSH TABLES WITH READ LOCK;
--echo # Copy s1.t1 files to tmp dir
--copy_files_wildcard $MYSQLD_DATADIR/s1/ $EXPORT_DIR t1*
UNLOCK TABLES;
DROP TABLE s1.t1;
DROP SCHEMA s1;

CREATE SCHEMA s2;
--echo # Copy t1 files into s2
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/s2/ t1*
--replace_regex /_[0-9]+\.sdi/_XXX.sdi/
--list_files $MYSQLD_DATADIR/s2

--error ER_IMP_SCHEMA_DOES_NOT_EXIST
IMPORT TABLE FROM 's2/t1*.sdi';
--remove_files_wildcard $MYSQLD_DATADIR/s2/ *
DROP SCHEMA s2;
--echo # Clean \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR *

--echo #
--echo # IM-NEG-1.1: Verfy that import using relative path to .sdi file
--echo # fails when not having a default schema.
--echo #
--echo # Connect without schema
connect (con_noschema,localhost,root,,*NO-ONE*);
--error ER_NO_DB_ERROR
IMPORT TABLE FROM 't1_*.sdi';
--echo # Don't need the current schema in this case, but check_access()
--echo # requires it
--error ER_NO_DB_ERROR
IMPORT TABLE FROM 's1/t1_*.sdi';

disconnect con_noschema;
connection default;

--echo #
--echo # IM-NEG-2: Table already exists in schema
--echo #
CREATE TABLE t1(i VARCHAR(32)) ENGINE MYISAM;
INSERT INTO t1 VALUES ('abc'), ('DEF'), ('Ghi'), ('ghI');
SELECT i FROM t1 ORDER BY i;

--error ER_IMP_TABLE_ALREADY_EXISTS
IMPORT TABLE FROM 't1*.sdi';

DROP TABLE t1;


--echo #
--echo # IM-NEG-3: Detection/diagnosis of non-matching pattern.
--echo #
--error ER_IMP_NO_FILES_MATCHED
IMPORT TABLE FROM 'pattern_which_matches_nothing';

--echo #
--echo # IM-NEG-4: Detection/diagnosis of access to path not permitted by
--echo # --secure-file-priv setting
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--error ER_OPTION_PREVENTS_STATEMENT,ER_OPTION_PREVENTS_STATEMENT
eval IMPORT TABLE FROM '$MYSQL_TEST_DIR/t/import.test';

--echo #
--echo # IM-NEG-5: Detection/diagnosis of corrupted SDI
--echo #
CREATE TABLE t1 (i int) ENGINE MYISAM;

--error ER_WRONG_FILE_NAME
IMPORT TABLE FROM 't1.MYD';

--copy_file $MYSQLD_DATADIR/test/t1.MYD $MYSQLD_DATADIR/test/t1.sdi
--error ER_INVALID_JSON_DATA
IMPORT TABLE FROM 't1.sdi';
DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.sdi

--echo #
--echo # IM-NEG-5.1: Verfy that import of an .sdi file which is valid json, but
--echo # corrupt at the application level is handled correctly.
--echo #

CREATE TABLE t1(i INT) ENGINE MYISAM;
--echo # Save SDI file in export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t1_*.sdi
DROP TABLE t1;
--echo # Create new version of t1
CREATE TABLE t1(i VARCHAR(32)) ENGINE MYISAM;
INSERT INTO t1 VALUES ('AAA'), ('BBB'), ('CCC');
FLUSH TABLES WITH READ LOCK;
--echo # Export .MYD and .MYI of the new t1
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t1.MY*
UNLOCK TABLES;
DROP TABLE t1;

--echo # First attempt to import without having copied back the data files,
--echo # which will fail
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t1_*.sdi
--error ER_FILE_NOT_FOUND
IMPORT TABLE FROM 't1_*.sdi';

--echo # Restore .MYD and .MYI of the new t1
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t1*
--echo # Import t1 using the old SDI file. Will succeed with warning since
--echo # we cannot open the imported table
IMPORT TABLE FROM 't1_*.sdi';

--echo # Try to repair table as suggested in warning (will not work in
--echo # this case)
REPAIR TABLE t1;
DROP TABLE t1;

--echo # Clean datadir and \$EXPORT_DIR
--remove_files_wildcard $MYSQLD_DATADIR/test/ t1*
--remove_files_wildcard $EXPORT_DIR *

--echo #
--echo # IM-NEG-6: Verify that concurrent use (from other threads)
--echo # of names of objects involved in import are detected,
--echo # and rejected as appropriate.
--echo #
CREATE TABLE t1(i INT) ENGINE MYISAM;
LOCK TABLES t1 WRITE;

--echo # Start new connection which will attempt to import locked table
connect (importcon,localhost,root,,);
SET @@session.lock_wait_timeout= 1;
--error ER_LOCK_WAIT_TIMEOUT
IMPORT TABLE FROM 't1_*.sdi';

--echo # Switch back to default and disconnect import connection
connection default;
disconnect importcon;

UNLOCK TABLES;
DROP TABLE t1;


--echo #
--echo # IM-NEG-7: Verify that SDI version mismatch is
--echo # diagnosed appropriately.
--echo #
CREATE TABLE t1(i INT) ENGINE=MYISAM;

--echo # Copy SDI file to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t1_*.sdi

--echo # Use perl to patch sdi_version in SDI file
--perl
opendir(TMP, "$ENV{'MYSQL_TMP_DIR'}/export");
chdir "$ENV{'MYSQL_TMP_DIR'}/export";
while ($_= readdir(TMP))
{
  next unless (/(.+)_\d+\.sdi/);
  my $base= $1;
  rename $_, "${base}.sdi";
}
closedir(TMP);
open(T1, "t1.sdi");
open(T1_, ">t1_.sdi");
while (<T1>)
{
  s/("sdi_version": ?)\d+,/${1}42,/g;
  print T1_ $_;
}
close(T1);
close(T1_);
EOF

--echo # Copy SDI file back into data dir
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t1_.sdi

# List error twice to avoid echoing error message, which will contain the
# current server version number
--error ER_IMP_INCOMPATIBLE_SDI_VERSION,ER_IMP_INCOMPATIBLE_SDI_VERSION
IMPORT TABLE FROM 't1_.sdi';
DROP TABLE t1;
--remove_files_wildcard $EXPORT_DIR *
--remove_files_wildcard $MYSQLD_DATADIR/test/ t1_.sdi


--echo #
--echo # IM-NEG-8 Verify that CREATE and FILE privileges are required
--echo # for IMPORT
--echo #
--echo # Create schema which does not match test* pattern which has special
--echo # privileges
CREATE SCHEMA s1;
CREATE TABLE s1.t1(i INT) ENGINE MYISAM;
--echo # Create user without any privileges.
CREATE USER noimportforyou@localhost;
REVOKE ALL ON *.* FROM noimportforyou@localhost;

--echo # Connect as user noimportforyou@localhost;
connect (con_noimport,localhost,noimportforyou,,);

--echo # Should fail due to missing privileges
--error ER_ACCESS_DENIED_ERROR
IMPORT TABLE FROM 's1/t1_*.sdi';

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;
GRANT FILE ON *.* TO noimportforyou@localhost;

--echo # Connect as user noimportforyou@localhost - now with FILE privilege
connect (con_noimport,localhost,noimportforyou,,);
--echo # Should fail due to missing CREATE privilege
--error ER_TABLEACCESS_DENIED_ERROR
IMPORT TABLE FROM 's1/t1_*.sdi';

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;
--echo # Grant general CREATE privilege
GRANT CREATE ON *.* TO noimportforyou@localhost;
--echo # Connect as user noimportforyou@localhost - now with FILE & CREATE
--echo # privilege
connect (con_noimport,localhost,noimportforyou,,s1);

--echo # Should have sufficient privileges, but fail because t1 already exist
--error ER_IMP_TABLE_ALREADY_EXISTS
IMPORT TABLE FROM 't1_*.sdi';
--list_files $MYSQLD_DATADIR/test t*

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;
--echo # Revoke general CREATE privilege
REVOKE CREATE ON *.* FROM noimportforyou@localhost;
--echo # Grant CREATE privilege on s1 schema
GRANT CREATE ON s1.* TO noimportforyou@localhost;

--echo # Connect as user noimportforyou@localhost - now with FILE & CREATE
--echo # privilege on s1.*
connect (con_noimport,localhost,noimportforyou,,s1);
--echo # Should have sufficient privileges, but fail because t1 already exist
--error ER_IMP_TABLE_ALREADY_EXISTS
IMPORT TABLE FROM 't1_*.sdi';

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;
--echo # Revoke CREATE privilege on s1 schema
REVOKE CREATE ON s1.* FROM noimportforyou@localhost;
--echo # Grant CREATE privilege on s1.t1
GRANT CREATE ON s1.t1 TO noimportforyou@localhost;

--echo # Connect as user noimportforyou@localhost - now with FILE & CREATE
--echo # privilege on test.t1
connect (con_noimport,localhost,noimportforyou,,s1);

--echo # Should have sufficient privileges, but fail because t1 already exist
--error ER_IMP_TABLE_ALREADY_EXISTS
IMPORT TABLE FROM 't1_*.sdi';

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;
--echo # Revoke FILE privilege
REVOKE FILE ON *.* FROM noimportforyou@localhost;

--echo # Connect as user noimportforyou@localhost - now with only CREATE
--echo # privilege on test.t1
connect (con_noimport,localhost,noimportforyou,,s1);

--echo # Should fail due to missing FILE privilege
--error ER_ACCESS_DENIED_ERROR
IMPORT TABLE FROM 't1_*.sdi';

--echo # Disconnect and switch back to default connection
disconnect con_noimport;
connection default;

DROP USER noimportforyou@localhost;
DROP TABLE s1.t1;
DROP SCHEMA s1;


--echo #
--echo # IM-POS-2: Export, drop and import back table
--echo #
CREATE TABLE t1 (i INT) ENGINE=MYISAM;
INSERT INTO t1 VALUES (1), (3), (5);
SELECT * FROM t1;
CREATE TABLE t2 (i INT) ENGINE=MYISAM;
INSERT INTO t2 VALUES (2), (4), (6);
SELECT * FROM t2;
CREATE VIEW v2 AS SELECT * FROM t2;
SELECT * FROM v2;

FLUSH TABLES WITH READ LOCK;
--echo # Copy t1 files to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t*
UNLOCK TABLES;
DROP TABLE t1;
DROP TABLE t2;
--echo # Check that the view is now invalid.
CHECK TABLE v2;
--echo # Copy files back into datadir
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t*
IMPORT TABLE FROM 't1_*.sdi', 't2_*.sdi';
SHOW CREATE TABLE t1;
SHOW CREATE TABLE t2;
SELECT * FROM t1;
SELECT * FROM t2;
--echo # Check that the view is now valid.
CHECK TABLE v2;
SELECT * FROM v2;
DROP VIEW v2;
DROP TABLE t1;
DROP TABLE t2;
--echo # Clean SDI files in \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR t*

--echo #
--echo # IM-POS-3: Verfiy that the .sdi file can be manually edited
--echo # (e.g. the schema name is changed, the name of a column).
--echo #
CREATE TABLE t1 (i INT) ENGINE MYISAM;
INSERT INTO t1 VALUES (1), (3), (5);
SELECT * FROM t1 ORDER BY i;
FLUSH TABLES WITH READ LOCK;
--echo # Copy t1 files to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t*
UNLOCK TABLES;
DROP TABLE t1;

--echo # Use perl to rename and patch SDI file
--perl
opendir(TMP, "$ENV{'MYSQL_TMP_DIR'}/export");
chdir "$ENV{'MYSQL_TMP_DIR'}/export";
while ($_= readdir(TMP))
{
  next unless (/(.+)_\d+\.sdi/);
  my $base= $1;
  rename $_, "${base}.sdi";
}
closedir(TMP);
open(T1, "t1.sdi");
open(T1_, ">t1_.sdi");
while (<T1>)
{
 s/("name": ?)"i"/$1"k"/g;
 print T1_ $_;
}
close(T1);
close(T1_);
EOF

--list_files $EXPORT_DIR
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t1*
IMPORT TABLE FROM 't1_.sdi';
SELECT * FROM t1 ORDER BY k;
DROP TABLE t1;
--echo # Clean \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR *
--echo # Clean \$DATA_DIR/test
--remove_files_wildcard $MYSQLD_DATADIR/test t1*

--echo #
--echo # IM-POS-4: Verify that at table can be imported into a schema
--echo # with a different collation id
--echo #

CREATE SCHEMA s1;
CREATE TABLE s1.t1(i VARCHAR(32)) ENGINE MYISAM;
INSERT INTO s1.t1 VALUES ('abc'), ('DEF'), ('Ghi'), ('ghI');
SELECT I FROM s1.t1 ORDER BY i;

FLUSH TABLES WITH READ LOCK;
--echo # Copy s1.t1 to export dir
--copy_files_wildcard $MYSQLD_DATADIR/s1/ $EXPORT_DIR t1*
UNLOCK TABLES;

DROP TABLE s1.t1;
ALTER SCHEMA s1 DEFAULT COLLATE latin1_bin;

--echo Copy MYD and MYI back into datadir
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/s1/ t1*

IMPORT TABLE FROM 's1/t1*.sdi';
--replace_regex /_[0-9]+\.sdi/_XXX.sdi/
--list_files $MYSQLD_DATADIR/s1
--echo # Verfy that collation for t1 has not changed
SELECT i FROM s1.t1 ORDER BY i;
SHOW CREATE TABLE s1.t1;

--echo # Create new table which will get the s1's new default collation
CREATE TABLE s1.t2(i VARCHAR(32));
INSERT INTO s1.t2 VALUES ('abc'), ('DEF'), ('Ghi'), ('ghI');
--echo # Verify that the collation for t2 is different
SELECT I FROM s1.t2 ORDER BY i;
SHOW CREATE TABLE s1.t2;

DROP TABLE s1.t1;
DROP SCHEMA s1;

--echo # Clean \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR *

--echo #
--echo # IM-POS-5: Verify that concurrent DROP SCHEMA|DATABASE, after the
--echo # data and index files to import have been placed in the schema dir,
--echo # fails because it is unable to delete the schema directory. Verify
--echo # that manual intervention can fix the problem.
--echo #
CREATE SCHEMA s1;
CREATE TABLE s1.t1(i VARCHAR(32)) ENGINE MYISAM;
INSERT INTO s1.t1 VALUES ('abc'), ('DEF'), ('Ghi'), ('ghI');
SELECT i FROM s1.t1 ORDER BY i;

FLUSH TABLES WITH READ LOCK;
--echo # Copy t1 to tmp dir
--copy_files_wildcard $MYSQLD_DATADIR/s1/ $EXPORT_DIR t1*
UNLOCK TABLES;
DROP TABLE s1.t1;

--echo # Copy t1 files back into s1
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/s1/ t1*

--echo # Drop s1 which is empty in DD, but which has files in directory
#--error ER_DB_DROP_RMDIR,ER_DB_DROP_RMDIR
--disable_query_log
CALL mtr.add_suppression("Problem while dropping database. Can't remove database directory .* Please remove it manually.");
--enable_query_log
--replace_result $MYSQLD_DATADIR ./ \\ /
--replace_regex /errno: [0-9]+ - .*\)/errno: ## - ...)/
DROP SCHEMA s1;
--echo # Show offending files
--list_files $MYSQLD_DATADIR/s1
--echo # Manual intervention which removes files...
--force-rmdir $MYSQLD_DATADIR/s1
#DROP SCHEMA s1;
CREATE SCHEMA s1;
--echo Copy t1 files back into s1
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/s1/ t1*
IMPORT TABLE FROM 's1/t1*.sdi';
SELECT i FROM s1.t1 ORDER BY i;

DROP TABLE s1.t1;
DROP SCHEMA s1;
--echo # Clean \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR *


--echo #
--echo # IM-POS-6: Import into server with l_c_t_n=true
--echo #
CREATE TABLE T_CASE(i INT) ENGINE MYISAM;
INSERT INTO T_CASE VALUES (1), (3), (5);
SELECT * FROM T_CASE ORDER BY i;
FLUSH TABLES WITH READ LOCK;
--echo # Copy T_CASE files to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR *
UNLOCK TABLES;
DROP TABLE T_CASE;

--echo # Use perl to rename and patch SDI file
--perl
opendir(TMP, "$ENV{'MYSQL_TMP_DIR'}/export");
chdir "$ENV{'MYSQL_TMP_DIR'}/export";
while ($_= readdir(TMP))
{
  if (/(.+)_\d+\.sdi/)
  {
    my $b= lc($1);
    rename $_, "${b}.sdi";
    next;
  }
  if (/(.+)\.MYD/)
  {
    my $b= lc($1);
    rename $_, "${b}.MYD";
    next;
  }
  if (/(.+)\.MYI/)
  {
    my $b= lc($1);
    rename $_, "${b}.MYI";
  }

}
closedir(TMP);
open(T1, "t_case.sdi");
open(T1_, ">t_case_.sdi");
while (<T1>)
{
  s/T_CASE/t_case/g;
  print T1_ $_;
}
close(T1);
close(T1_);
rename "t_case_.sdi", "t_case.sdi";
EOF

--list_files $EXPORT_DIR
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t_case*
IMPORT TABLE FROM 't_case.sdi';
SELECT i FROM t_case ORDER BY i;
DROP TABLE t_case;


--echo #
--echo # Start new server with --lower_case_table_names and import t_case there
--echo #

let BASEDIR=    `select @@basedir`;
let DDIR=       $MYSQL_TMP_DIR/lctn_test;
let MYSQLD_LOG= $MYSQL_TMP_DIR/server.log;
let extra_args= --no-defaults --innodb_dedicated_server=OFF --log-error=$MYSQLD_LOG --loose-skip-auto_generate_certs --loose-skip-sha256_password_auto_generate_rsa_keys --skip-ssl --lower_case_table_names=1 --basedir=$BASEDIR --lc-messages-dir=$MYSQL_SHAREDIR;
let BOOTSTRAP_SQL= $MYSQL_TMP_DIR/tiny_bootstrap.sql;

--echo # 0. Shut server down.
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--shutdown_server
--source include/wait_until_disconnected.inc

--echo # 1. Create bootstrap file.
write_file $BOOTSTRAP_SQL;
  CREATE SCHEMA test;
EOF

--echo # 2. First start the server with --initialize
--exec $MYSQLD $extra_args --secure-file-priv="" --initialize-insecure --datadir=$DDIR --init-file=$BOOTSTRAP_SQL

--echo # 3. Restart the server against DDIR - should succeed.
--exec echo "restart:" --datadir=$DDIR --lower_case_table_names=1 --secure-file-priv="" --no-console --log-error=$MYSQLD_LOG > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--enable_reconnect
--source include/wait_until_connected_again.inc

--echo # 4. Import file created on server without lctn
--echo # Copying exported t_case files into \$DDIR/test
--copy_files_wildcard $EXPORT_DIR $DDIR/test/ t_case*
--echo # Listing \$DDIR/test:
--list_files $DDIR/test

IMPORT TABLE FROM 't_case.sdi';
SELECT i FROM t_case ORDER BY i;
DROP TABLE t_case;

--echo # 5. Shut server down.
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--shutdown_server
--source include/wait_until_disconnected.inc

--echo # 6. Cleanup: Restarting the server against default datadir.
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--enable_reconnect
--source include/wait_until_connected_again.inc

--echo # Delete \$DDIR
--force-rmdir $DDIR

--echo # Delete sql files
--remove_files_wildcard $MYSQL_TMP_DIR *.sql

--echo # Delete log files
--remove_files_wildcard $MYSQL_TMP_DIR *.log

--echo # Delete expect files
--remove_files_wildcard $MYSQL_TMP_DIR *.expect

--remove_files_wildcard $EXPORT_DIR t_case*

--echo #
--echo # Bug#25792649: SDI DESERIALIZE MISSING COLUMNIMPL::M_NUMERIC_SCALE_NULL
--echo # Export, drop and import back table with columns that have attributes
--echo # which are null by default
--echo #
CREATE TABLE t1 (i INT DEFAULT 42, dt DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
                 de DECIMAL(10,2), j INT GENERATED ALWAYS AS (42+i)) ENGINE=MYISAM;
SHOW CREATE TABLE t1;
INSERT INTO t1(dt,de) VALUES ('2017-03-28 18:48:01', 1.1),
                             ('2017-03-28 18:48:02', 1.2),
                             ('2017-03-28 18:48:03', 1.5);
SELECT * FROM t1;

FLUSH TABLES WITH READ LOCK;
--echo # Copy t1 files to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t*
UNLOCK TABLES;
DROP TABLE t1;

--echo # Copy files back into datadir
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t*
IMPORT TABLE FROM 't1_*.sdi';
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
--echo # Clean SDI files in \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR t*


--echo #
--echo # Bug#25914953 ASSERTION FAILED: M_THD->GET_TRANSACTION()->
--echo # IS_EMPTY(TRANSACTION_CTX::STMT)
--echo #
--echo # Need to commit any existing txn before using Disable_autocommit_guard

START TRANSACTION WITH CONSISTENT SNAPSHOT;
--error ER_IMP_NO_FILES_MATCHED
IMPORT TABLE FROM '';

--echo #
--echo # Bug#17468242/Wl#11807: Provide an option to prevent creation of tables
--echo # without a unique/pk
--echo # Ensure that a PK-less table cannot be imported when
--echo # sql_require_primary_key is set

CREATE TABLE t1 (i INT) ENGINE=MYISAM;

FLUSH TABLES WITH READ LOCK;
--echo # Copy t1 files to export dir
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t*
UNLOCK TABLES;
DROP TABLE t1;

--echo # Copy files back into datadir
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t*

SET SESSION sql_require_primary_key= ON;
--error ER_TABLE_WITHOUT_PK
IMPORT TABLE FROM 't1_*.sdi';
--remove_files_wildcard $MYSQLD_DATADIR/test/ t*

SET SESSION sql_require_primary_key= OFF;
--echo # Clean SDI files in \$EXPORT_DIR
--remove_files_wildcard $EXPORT_DIR t*

--echo #-----------------------------------------------------------------------
--echo # WL#929 - Check constraint.
--echo # Test case to verify check constraint import from SDI.
--echo #-----------------------------------------------------------------------
CREATE TABLE t1 (f1 INT CHECK (f1 < 10)) ENGINE=MyISAM;
let $MYSQLD_DATADIR=`SELECT @@datadir`;
--copy_files_wildcard $MYSQLD_DATADIR/test/ $MYSQL_TMP_DIR/ t*
DROP TABLE t1;
--copy_files_wildcard $MYSQL_TMP_DIR/ $MYSQLD_DATADIR/test/ t*
IMPORT TABLE FROM 'test/t1*.sdi';
SHOW CREATE TABLE t1;
DROP TABLE t1;
--remove_files_wildcard $MYSQL_TMP_DIR/ t*

--echo # Remove 'export' folder created at the beginning of test file.
--force-rmdir $EXPORT_DIR