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
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)
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.Tagged as: system administration, sql, mysql, csv, how to, linux
<<First <Back | 1 | 2 | 3 | 4 | Next>