Advertisement: Over 100,000 Jobs Worldwide. Click here to find one for you.

MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
Send This Page to Friend
Enter Friend's Email
Enter Your Email
http://www.kareerlinks.com/jobs/skill/MySQL
 
Home / Data Back Up / Import Data / Question No: 175

How to import data from text file into table with LOAD DATA INFILE statement?

I want to import data from text file into MySQL table. Can you explain, how to import data from text file into table with  LOAD DATA INFILE statement?

Answer No: 175

MySQL LOAD DATA INFILE statement allows to import data into table.  This statement facilitates to import data of several formats like csv data, Microsoft Excel, text file and other delimited text files with wide array of options that make this feature so powerful. Suppose you want to import a text file titled authorlist.txt, which contains the following information:

'1','Kenneth James','kj@example.com','CA'
'2','Ashley Lawis','al@example.com','DC'
'3','Arnold Alister','aa@example.com','OH'

The target table, namely authors, consists of three fields, and they are in the same order (author_id, author_email, author_state) as the information found in authorlist.txt:

LOAD DATA LOCAL INFILE authorlist.txt' INTO TABLE authors 
FIELDS TERMINATED BY ',' ENCLOSED BY '\''
ESCAPED BY '\\' LINES TERMINATED BY '\n';

Comments
Add Comments
Found a bug? Or do you have a better solution for this? Feel free to leave a message:
Leave a comment
Your Name: Your Email Address (optional):
Comment:


Related MySQL FAQs to the Above FAQ

How-to-use-mysqlimport-client How to use mysqlimport client?

How-to-use-LOAD-DATA-INFILE-statement How to use LOAD DATA INFILE statement?

How-to-import-data-from-Microsoft-Excel-file-into-table-with-LOAD-DATA-INFILE-statement How to import data from Microsoft Excel file into table with LOAD DATA INFILE statement?