Useful CSV to MySQL Script

PHP/MySQL | Updated 2026

Importing CSV data into a MySQL/MariaDB database is a common task for populating product catalogs, contact lists, or migrating data from spreadsheets. Here are the best methods on your hosting account.

01. Import via phpMyAdmin

  1. Create the target table first with columns matching your CSV structure (or use an existing table)
  2. Select the table in phpMyAdmin
  3. Click "Import"
  4. Choose your CSV file
  5. Format: CSV
  6. Set the column separator (usually comma), text qualifier (usually double quote), and whether the first row contains column names
  7. Click "Go"

02. Import via SQL

Upload your CSV to your hosting account, then run this SQL in phpMyAdmin:

LOAD DATA LOCAL INFILE '/home/username/data.csv'
INTO TABLE tablename
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

The IGNORE 1 ROWS skips the header row if your CSV has column names.

Tip

If LOAD DATA LOCAL INFILE is disabled on the server (common on shared hosting for security), use the phpMyAdmin import method instead, or write a PHP script that reads the CSV with fgetcsv() and inserts rows via prepared statements.

For exporting data, see MySQL Import/Export Format. For phpMyAdmin usage, see View/Modify Data in MySQL.

Data Import Help?

Open a Support Ticket

Quick Recap

  1. phpMyAdmin Import is the easiest method
  2. Create the table first with matching columns
  3. Set CSV format options (separator, qualifier, header row)
  4. LOAD DATA INFILE for SQL-based import (may be restricted)
  5. Use fgetcsv() in PHP as an alternative

Database operations · Last updated March 2026 · Browse all PHP/MySQL articles

  • 135 Users Found This Useful

Was this answer helpful?

Related Articles

Clean - Shrink ibdata1

PHP/MySQL | Updated 2026 The ibdata1 file is the InnoDB system tablespace used by...

How do I import into a MariaDB - MySQL database?

PHP/MySQL | Updated 2026 Importing data into a MariaDB or MySQL database on your hosting...

InnoDB Error: Attempted to Open a Previously Opened Tablespace

Server Maintenance | Updated March 2026 The "Attempted to open a previously opened...

Increase PHP Memory

PHP/MySQL | Updated 2026 If your website shows a "Fatal error: Allowed memory size exhausted"...

How can I view/modify data in my MySQL database?

PHP/MySQL | Updated 2026 phpMyAdmin is the primary tool for viewing, editing, and managing...



Save 30% on web hosting - Use coupon code Hosting30