IPv6 Launchipv6 ready

How to import csv or txt file into MySQL table 

In system administration tasks it is likely that sooner or later you will have to import some data from a text file to a MySQL database.

It is as easy as the following SQL statement:

LOAD DATA LOCAL INFILE './filename.txt' INTO TABLE `tableName`  FIELDS TERMINATED BY ' ' (firstName,email)


The code above is assuming that the filename.txt have the content like:

John john@example.com
Steven steven@example.com
Erica erica@example.com


You can import csv by changing the
FIELDS TERMINATED BY ' '

to
FIELDS TERMINATED BY ','


Comments - How to import csv or txt file into MySQL table

Stanimir Stoyanov 

the load command can be used with any OS running MySQL. If you're passing the full file path using Windows you should use something like:
LOAD DATA LOCAL INFILE 'C:\temp\filename.txt' INTO TABLE `tableName`  FIELDS TERMINATED BY ' ' (firstName,email)


in Unix/Linux it will look like
LOAD DATA LOCAL INFILE '/home/somebody/mysqlimport/filename.txt' INTO TABLE `tableName`  FIELDS TERMINATED BY ' ' (firstName,email)


grails database guy 

Is this load command for Unix/Linux or can also be used on windows?

Add Comment

Fill out the form below to add your own comments.









Insert Special:






Moderation is turned on for this blog. Your comment will require the administrators approval before it will be visible.


Tagged as: , , , , ,

<<First <Back | 1 | 2 | 3 | 4 | Next>