mysql使用load命令导入SQL文件

67 阅读1分钟

一、环境

  • 数据库版本:mysql 5.7.39

二、操作步骤

#连接mysql加上--local-infile参数
mysql --local-infile -u root -p

#开启从本地加载文件导入数据的开关
mysql> set global local_infile=1;
#查询mysql默认的临时读写目录
mysql> show variables like '%tmpdir%';
image.png

将SQL文件上传至临时读写目录

#将数据文件导入到表中
mysql> load data infile '/tmp/load_user_100w_sort.sql' into table tb_user fields terminated by ',' lines terminated by '\n';

image.png