How to import .csv files in the database from phpMyAdmin

April 8, 2020 / MySQL

In this article, you will understand how to import .csv files in the database from phpMyAdmin.

To import a .csv file into a database using phpMyAdmin, save your Excel file as a CSV instead of a workbook. Open it in Notepad to ensure columns are separated by commas (,). Remove column headings, blank areas, and make sure each row and column contains data. The number of columns in the CSV file must match the database table.

To import .CSV file into database, follow these steps:

  1. Firstly, upload .csv file to the public_html directory. 
  2. Now, Open phpMyAdmin and select the database where you want to import .csv file. 
  3. Click on the SQL tab.
  4. Type following SQL query:
    LOAD DATA LOCAL INFILE 'Full path to .CSV file'
    INTO TABLE city
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n';
    Replace actual full path with “Full path for .CSV file” (/home/username/public_html/filename.csv)
  5. Click on Go.

With the help of above steps you can import .csv file into your database using phpMyAdmin. 

Spread the love