简体   繁体   中英

How to import large csv files to mysql?

I just want to ask a question about importing a csv files to mysql tables. Because i have a csv file that contains 43762 rows but when i loaded it im my table it only inserted 2181 rows. I just wondering if there's a bug in my mysql.

Here's the output of my insert code:

mysql> load data local infile 'c:/database/cities_table2.csv'
-> into table ref_draft
-> fields terminated by ','
-> enclosed by '"'
-> lines terminated by '\n'
-> (municipality,name);
Query OK, 2181 rows affected, 2 warnings (0.28 sec)
Records: 2181  Deleted: 0  Skipped: 0  Warnings: 2

mysql> select count(*) from ref_draft;
+----------+
| count(*) |
+----------+
|     2181 |
+----------+
1 row in set (0.00 sec)

Is there other way to import large files?

Did you turn off indexing? Also, make sure there's not a lot of incoming activity so you don't "hog" the server resources.

Ok i solved my problem I just need to replace

lines terminated by '\n' 

to

lines terminated by '\r\n'

Thanks for the immediate response sir.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM