How to Import Excel or CSV File to MySQL Table


If you are a MySQL user, its most likely that you would have come across a need for importing the data in the Excel or CSV files directly to you MySQL tables. The ‘LOAD DATA LOCAL INFILE’ command supported by MySQL can help you to achieve your purpose.  Below is the syntax for using this command,

LOAD DATA LOCAL INFILE ‘C:\\test\\userData.csv’ INTO TABLE User FIELDS TERMINATED BY ‘,’ (name,email,address)

In the above command, I am inserting the data into three of the columns in the ‘User’ table directly from the ‘userData.csv’ file. If you have the data in an Excel file, you need to convert it to a CSV file before using this command. Also, make sure you don’t have any column headers in the file before using this command. 

If you enjoyed this article, Get email updates (It’s Free)


About the author

Prasanna LM is a Software Engineer and a Tech Enthusiast from Bengaluru,India. He is the founder and Chief Blogger at TechSagar.com. Prasanna specializes in developing Software's using Java and related technologies. He also advice's novice bloggers in setting up self hosted WordPress blogs.