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

Server Paths - PHP Perl Python and More

PHP/MariaDB/MySQL | Updated March 2026 The default path to PHP on Ultra Web Hosting servers...

How do I backup a MariaDB - MySQL Database?

PHP/MySQL | Updated 2026 Backing up your database is essential before making changes to your...

Test MySQL Connection

PHP/MySQL | Updated 2026 If your website shows database connection errors, you need to verify...

How Do I Update or Change My PHP Version

Hosting Control Panel | Updated March 2026 Ultra Web Hosting runs CloudLinux with multiple...

Learn About MariaDB

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



Save 30% on web hosting - Use coupon code Hosting30