MySQL 导入文件数据
1. mysql 语句
LOAD DATA LOCAL INFILE "xxx/xxx/xxx.xxx" INTO TABLE `xxx`.`xxx`;
报错
ERROR 1148 (42000): The used command is not allowed with this MySQL version
2. 解决错误
2.1 改表
把
local_infile
中的 值从 off 改为ON
/* 查看 local_infile */
show global variables like 'local_infile';
/* off 改为 ON */
set global local_infile = 'ON';
再次查看结果
2.2 从新登入 MySQL
退出
/* 退出 mysql */
\q
从新登入
/* 登入 mysql */
mysql --local-infile=1 -u root -p
按上面从新登录在执行 MySQL 导入文件数据的语句
3. 进阶
LOAD DATA LOCAL INFILE "xxx/xxx/xxx.xxx" INTO TABLE `xxx`.`xxx` fields terminated by 'xx' optionally enclosed by 'xx' lines terminated by 'xx';
1. LOAD DATA LOCAL INFILE "xxx\xxx\xxx.xxx": 导入数据的文件名路径加上文件名.
2. INTO TABLE `xxx`.`xxx`: 导入数据到那个数据库中的那个表.
3. fields terminated by 'xx': 以 xx 为分隔符.
4. optionally enclosed by 'xx': 去掉包围字段内容的 xx.
5. lines terminated by 'xx': 以 xx 为行尾符.