This guide will discover the steps required to import .cvs files in database from phpMyAdmin.
Follow the steps to import .csv files in database:
- Save Your File in the Correct Format:
- Convert your Excel file to a .csv format.
- Do not save it as a workbook or any other format.
- Verify the file using a text editor (e.g., Notepad) to ensure each column is separated by a comma (,).
- Prepare Your Data:
- Remove column headers and blank spaces.
- Ensure every row and column contains valid data.
- The structure of the .csv file should exactly match your database table. If your table has n columns, your CSV file must also have n columns.
Steps to Import a .CSV File into a Database:
- Upload the .csv file: Use FTP to upload your .csv file to the public_html directory.
- Access phpMyAdmin:
- Open phpMyAdmin.
- Select your database.
- Click on the SQL tab.
- Run the SQL Query:
Execute the following query, replacing the placeholder with the actual file path:LOAD DATA LOCAL INFILE 'Full path to .CSV file' INTO TABLE city FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Example:
LOAD DATA LOCAL INFILE '/home/username/public_html/filename.csv' INTO TABLE city FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
- Click on “Go” to execute the query.
That’s it! Importing .csv files into a database using phpMyAdmin is simple. Its user-friendly interface makes managing large datasets efficient and hassle-free.