LOAD DATA INFLIE优点速度快
普通的导入和导出都是使用insert,如果数据量很大的话,速度会比较慢,使用LOAD DATA INFLIE ,比一般的insert语句快20倍。
演示:
1、查看默认导出目录
SHOW VARIABLES LIKE "secure_file_priv";
结果:C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\
2、导出数据到默认目录下的文件
select * INTO OUTFILE "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\product.txt" from product;
注意:不使用默认目录会报错:The MySQL server is running with the --secure-file-priv option so it cannot execute
查看导出的文件结构:和普通的insert很不一样
3、导入数据
load data INFILE 'C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\product.txt'
into table product
导入成功:速度很快