赞助商

MySql文件导入(LOAD DATA LOCAL INFILE)

发布时间:2019-04-12 发布网站:脚本之家
脚本之家收集整理的这篇文章主要介绍了MySql文件导入(LOAD DATA LOCAL INFILE)脚本之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一张叫做城市的桌子:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| country_id | mediumint(9) | NO   | MUL | NULL    |                |
| region_id  | bigint(20)   | NO   | MUL | NULL    |                |
| city       | varchar(45)  | NO   |     | NULL    |                |
| latitude   | float(18,2)  | NO   |     | NULL    |                |
| longitude  | float(18,2)  | NO   |     | NULL    |                |
| timezone   | varchar(10)  | NO   |     | NULL    |                |
| dma_id     | mediumint(9) | YES  |     | NULL    |                |
| code       | varchar(4)   | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

我有一个简单的文件(只是一个测试文件)来导入:

"id","country_id","region_id","city","latitude","longitude","timezone","dma_id","code"
42231,1,833,"Herat","34.333","62.2","+04:30","HERA"
5976,835,"Kabul","34.517","69.183","+04:50","KABU"
42230,852,"Mazar-e Sharif","36.7","67.1","+4:30","MSHA"
42412,2,983,"Korce","40.6162","20.7779","+01:00","KORC"
5977,1011,"Tirane","41.333","19.833","TIRA"
5978,3,856,"Algiers","36.763","3.051","ALGI"
5981,858,"Skikda","36.879","6.907","SKIK"
5980,861,"Oran","35.691","-0.642","ORAN"

我运行这个命令:

LOAD DATA LOCAL INFILE 'cities_test.txt' INTO TABLE city FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;

输出:

Query OK,0 rows affected (0.00 sec)
Records: 0  Deleted: 0  Skipped: 0  Warnings: 0

没有插入记录,我不知道为什么.

有任何想法吗?

谢谢!

杰米

最佳答案
解决了这个问题.愚蠢的错误.

不得不改变这个:

LINES TERMINATED BY '\r\n'

对此:

LINES TERMINATED BY '\n'

总结

以上是脚本之家为你收集整理的MySql文件导入(LOAD DATA LOCAL INFILE)全部内容,希望文章能够帮你解决MySql文件导入(LOAD DATA LOCAL INFILE)所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:76874919,请注明来意。