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

How do I change my PHP settings?

Updated 2026 Quick Answer To change PHP settings like upload_max_filesize,...

Learn About MariaDB

PHP/MySQL | Updated 2026 Ultra Web Hosting uses MariaDB as the database server on all shared...

Learn About MySQL

Databases | Updated 2026 MariaDB (the MySQL-compatible database server on Ultra Web Hosting)...

Clean - Shrink ibdata1

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

InnoDB Error: Attempted to Open a Previously Opened Tablespace

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



Save 30% on web hosting - Use coupon code Hosting30