select @@global.secure_file_priv; SET FOREIGN_KEY_CHECKS = 0; drop database if exists test; create database test; use test; drop table if exists t1; CREATE TABLE `t1` ( `ID` int NOT NULL, primary key `PK0` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; drop procedure if exists load_foo_test_data; delimiter # create procedure load_foo_test_data() begin declare v_max int unsigned default 9000; declare v_counter int unsigned default 0; truncate table t1; start transaction; while v_counter < v_max do insert into t1 (ID) values (v_counter); set v_counter=v_counter+1; end while; commit; end # delimiter ; call load_foo_test_data(); SELECT COUNT(*) FROM t1; SELECT * FROM t1 INTO OUTFILE '/tmp/t1.csv'; ## import ## Create an empty table drop table if exists parent; drop table if exists child; CREATE TABLE `parent` ( `ID` int NOT NULL, primary key `PK1` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; # #CREATE TABLE `child` ( # `ID` int NOT NULL, # primary key `PK2` (`ID`), # CONSTRAINT `CO3` FOREIGN KEY (`ID`) REFERENCES `parent` (`ID`) #) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `ID` int NOT NULL, primary key `PK2` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; LOAD DATA INFILE '/tmp/t1.csv' IGNORE INTO TABLE child; SELECT COUNT(*) FROM child; ALTER TABLE child add CONSTRAINT `CO4` FOREIGN KEY (`ID`) REFERENCES `parent` (`ID`), algorithm=copy; SHOW CREATE TABLE child;