Menu

How to Convert CSV to MySQL INSERT Statements

Convert CSV or spreadsheet data into MySQL CREATE TABLE and batched INSERT statements with type inference, NULL handling, escaping, and browser-local processing.

Posted on By
On this page

A CSV file can be loaded into MySQL in several ways. For large imports, LOAD DATA INFILE is usually the better bulk-loading tool. But for seed data, migrations, test fixtures, or one-off imports, a readable SQL script can be more convenient.

The SQLiz CSV to SQL Converter can generate MySQL CREATE TABLE and batched INSERT statements directly in your browser.

Example CSV

Suppose your CSV contains:

id,name,department,salary
1,Ada,Engineering,95000.50
2,Grace,Platform,102500.00
3,Alan,Research,110000.00

A MySQL script can look like:

CREATE TABLE employees (
  id INT,
  name VARCHAR(255),
  department VARCHAR(255),
  salary DECIMAL(10,2)
);

INSERT INTO employees (
  id,
  name,
  department,
  salary
)
VALUES
  (1, 'Ada', 'Engineering', 95000.50),
  (2, 'Grace', 'Platform', 102500.00),
  (3, 'Alan', 'Research', 110000.00);

Generate MySQL SQL from CSV

Open the CSV to SQL Converter and choose MySQL/MariaDB as the target dialect.

Then:

  1. paste CSV text or open a local file
  2. confirm the detected delimiter
  3. enter the destination table name
  4. review inferred column types
  5. choose how empty fields should be treated
  6. generate the SQL
  7. copy or download the result

The CSV content is processed locally in your browser.

Escaping text values

CSV fields can contain apostrophes and commas.

For example:

id,name
1,O'Connor
2,"Smith, Alice"

The generated SQL needs correct string escaping:

INSERT INTO people (id, name)
VALUES
  (1, 'O''Connor'),
  (2, 'Smith, Alice');

The converter handles SQL string escaping for generated values.

NULL versus empty string

An empty CSV field may need to become either:

NULL

or:

''

Those values behave differently in MySQL.

Use the converter’s empty-value setting based on the meaning of the source data.

Batch INSERT statements

For multiple rows, MySQL supports multi-row inserts:

INSERT INTO employees (id, name)
VALUES
  (1, 'Ada'),
  (2, 'Grace'),
  (3, 'Alan');

Batching keeps generated scripts shorter and reduces the number of statements.

For larger import jobs, see SQL Bulk and Batch Insert by Database.

When LOAD DATA is better

If the CSV contains hundreds of thousands or millions of rows, generating a large SQL script is usually less efficient than MySQL’s native bulk-loading tools.

Use generated INSERT statements when you want:

  • a script you can review
  • seed data in source control
  • a small migration
  • a reproducible test dataset
  • an import method that does not depend on server-side file access

Use LOAD DATA INFILE or another bulk loader when throughput is the main goal.

Format the generated SQL

After conversion, you can send the script to the MySQL SQL Formatter for consistent indentation.

For the general workflow across multiple database systems, see How to Convert CSV to SQL INSERT Statements.