4/17/12

Import a CSV file to MySQL via phpMyAdmin

After getting requests for this tutorial from our readers on this topic, we decided to do a post on it.

If you also want to request a tutorial then feel free to use the "Request a Tutorial Here" link and send us a request for FREE.

According to the request the task was to import a CSV file to MySQL DB. 

So for that first, I went to the the main phpMyAdmin page. 

Next, I clicked on the database instance that I am interested. Then, I click on the table that I want to import my data and click on Import button. 

On the import form, I click Browse button to choose the CSV file on my local hard drive. Since my CSV file uses “|” to separate each fields and “\n” to separate each records, I chose the following options:

Choose CSV using LOAD DATA

Fields terminated by : ,
Fields enclosed by : [remove default value and leave it blank]
Fields escaped by : [remove default value and leave it blank]

Leave everything else to default value.

Finally, I clicked the Go button. This resulted the following SQL query. 

Note, I renamed values that are specific to my environment. So this is just for your reference only.

Below is the query that you will get :

LOAD DATA LOCAL INFILE 'input_file' INTO TABLE `tablename` FIELDS TERMINATED BY ',' LINES TERMINATED

SHARE THIS POST:

1 comment:

  1. Thanks for sharing informative article!!! Your article helped me a lot to understand the importance of PHP Training in Chennai to secure lucrative job in web design and development industry.

    ReplyDelete