红联Linux门户
Linux帮助

Linux下MySQL导入文件出错ERROR 1290 (HY000)

发布时间:2016-11-18 09:35:03来源:linux网站作者:char*
最近在进行MySQL学习时,发现导入文件一直出错,显示ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement。
 
看了网上的很多办法都不成功,后来发现原来是因为在MySQL 5.7.6版本之后,导入文件只能在secure_file_priv指定的文件夹下
所以用show variables like '%secure%';命令显示文件目录
Linux下MySQL导入文件出错ERROR 1290 (HY000)
 
这样将导入文件放在 /var/lib/mysql-files/文件夹下,之后再从这里导入就可以了。
 
load data infile '/var/lib/mysql-files/part.csv' into table PART fields terminated by ','  optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';
 
如果显示ERROR 1261 (01000): Row 1 doesn't contain data for all columns
这个错误,是因为数据行不匹配,默认不能有空,用下列命令解决
set sql_modul = 0;
 
参考内容:
在 MySQL 中使用 load data infile 命令导入数据文件到 MySQL 数据库中的时候,如果遇到 MySQL 错误:“ERROR 1261 (01000)” ,则很可能是由于数据文件中的列数跟 MySQL 数据表字段数目没有完全匹配,并且 sql_mode 设为 strict 模式的缘故。要想在这种情况下继续导入数据到 MySQL 表中,则需要设置 MySQL sql_mode 变量。把“strict_trans_tables” 从 sql_mode 中去掉,如下:
查看 MySQL 当前连接的 sql_mode
mysql> show variables like 'sql_mode';
Linux下MySQL导入文件出错ERROR 1290 (HY000)
设置 MySQL sql_mode,使其不包含 “strict_trans_tables” mode
找到办法了。
set sql_mode='';
这样,就可以利用 MySQL load data infile,继续向 MySQL 中导入数据了。否则,MySQL 会终止导入过程,并抛出下面几种错误信息:
ERROR 1261 (01000): Row 1 does not contain data for all columns
ERROR 1262 (01000): Row 1 was truncated; it contained more data than there were input columns
 
本文永久更新地址:http://www.linuxdiyf.com/linux/26091.html