Map Extract
Free tool

Convert SQL INSERT statements to CSV

Paste INSERT statements from a database dump, a backup or a developer's export and get the rows back as a CSV with the column names as the header. Multi-row inserts, doubled quotes and NULL values are all handled.

Runs in your browser. Nothing you enter is uploaded.

Two INSERT statements, three rows

The first statement inserts two rows at once and contains an escaped apostrophe and a NULL. The second inserts a row whose name contains a comma.

The column list from the first statement becomes the header. O''Neill is unescaped to O'Neill, NULL becomes an empty cell, and the name with a comma is quoted in the CSV so it stays in one column. The note reports 2 INSERT statements and 3 rows.

Input
INSERT INTO stockists (business, town, reviews) VALUES ('Kiln & Co Pottery', 'Frome', 48), ('O''Neill Plumbing', 'York', NULL);
INSERT INTO stockists (business, town, reviews) VALUES ('Pip, Parsnip & Co', 'Wells', 7);
Result
business,town,reviews
Kiln & Co Pottery,Frome,48
O'Neill Plumbing,York,
"Pip, Parsnip & Co",Wells,7

Converting a dump

  1. Find the INSERT lines

    Open the .sql file in a text editor and copy the INSERT INTO statements for the table you want. CREATE TABLE and other statements can be included; they are skipped.

  2. Paste them in

    The CSV appears immediately, with a note of how many statements and rows were read.

  3. Check the header

    Column names come from the column list in the INSERT. Make sure the statements you pasted all belong to the same table.

  4. Copy or download

    Copy the CSV or save data.csv and open it in a spreadsheet.

Things to watch in real dumps

Dumps from tools such as mysqldump often put thousands of rows in one INSERT, and that is fine. What matters is that each statement follows the INSERT INTO table (columns) VALUES (...) pattern. Rows from a statement without a column list are still read. When other statements do name their columns, those rows go under extra headings called column_1, column_2 and so on, so you can match them to the table definition yourself.

A dump may hold several tables. Paste only the statements for one table at a time, otherwise rows with different columns end up mixed together. And a backup of a customer or contact table is personal data: keep the CSV somewhere access is controlled, and delete working copies when you are done.

  • Values in single quotes, with doubled single quotes inside, are unescaped.
  • Values in double quotes, which MySQL accepts, are read like single-quoted ones, without the quote marks.
  • NULL is written as an empty cell, and numbers are copied as written.
  • If no INSERT INTO ... VALUES statement is found, an error says so.

Questions people ask

How do I convert a SQL file to CSV without a database?

Open the .sql file in any text editor, copy the INSERT INTO statements for the table you want, and paste them here. The rows are read directly from the statements, so you do not need MySQL, PostgreSQL or any other database running. Download the CSV and open it in Excel.

Does it handle inserts with many rows each?

Yes. A statement with VALUES (...), (...), (...) produces one CSV row per bracketed group, and several statements are combined into one file. The note shows how many statements and rows were found, so you can check the total against what you expected from the dump.

What happens to NULL values?

NULL is written as an empty cell, which is how most spreadsheets and import tools represent a missing value. If you need to tell a real empty string apart from NULL, replace NULL with a marker such as \N in the SQL before converting.

Can it read a whole database backup file?

It reads INSERT statements, so it can take a large part of a backup, but the result is clearest when you paste one table's statements at a time. Very large dumps are better split in a text editor first, because the whole paste is held in your browser's memory.

Where your data goes

The statements are parsed in your browser. No SQL is executed anywhere, and the data is not uploaded to Map Extract or any other server.

Checked against the tool on

Top