Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

importing csv file into mysql

Status
Not open for further replies.

yahoo182

Programmer
Jul 5, 2005
70
CA
Hi I have a rather big csv file (exported from excel) and I am trying to import this into mySql db with the follwoing code.

Code:
mysql > load data local infile '/home/kkohakur/Hotel_All_Active07-05-05.csv'
    -> into table hotelinfo
    -> fields terminated by ','
    -> lines terminated by '\n'
    -> (HotelID,Name,AirportCode,Address1,Address2,Address3,City,StateProvince,Country,PostalCode,Longitude,Latitude,LowRate,HighRate,MarketingLevel,Confidence,HotelModified,PropertyType);

This code imports the data correctly, but only up till a 1000 records/rows, and I have a lot more records in the original csv file (around 50,000).

Does anyone know how I may be able to import all of the data?

The response I get form running the command is

Code:
Query OK, 58887 rows affected (6.53 sec)
Records: 58887  Deleted: 0  Skipped: 0  Warnings: 58909

Thanks
 
I think i figured it out.
I was using mysqlCC and the default setting was to show 1000.
To overcome this, we can write something like
Code:
select * from hoteldb limit 50000
 
You might also want to pay attention to the warnings given, which probably indicate values that were not stored correctly. Are any of the fields enclosed in double-quotes? If so, you would need to say:[tt]
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'[/tt]
 
Hi there Tony.
Thanks for the tip. Does anyone know how we can actually see the contents of the warning messages?
Also, I see that the warning message is more than the rows of records actually ...
 
You can get the warnings for the latest command by using:[tt]
SHOW WARNINGS;[/tt]
 
Hi there TonyGroves
I tried your code
Code:
fields terminated by '|' OPTIONALLY ENCLOSED BY '"'
but then the fields that are enclosed in quotes do not get imported totally into the db. What I was would like is to have them imported, but without the quotation marks around them.

Is this possible?

thanks :)
 
You need to play around with the import options to suit the format of the file data. Since the data was exported from a reputable spreadsheet program, it should be valid CSV format, and you should be able to come up with suitable import options.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top