SQL to CSV
Extract data from SQL to CSV
About SQL to CSV
SQL to CSV reads the INSERT INTO … VALUES statements in pasted SQL, such as a mysqldump export, and writes their rows as CSV with a header row. Multi-row inserts, INSERT IGNORE, names in backticks, double quotes, or brackets, and schema.table names are read. The header comes from the column list, or is column_1, column_2, and so on when there is none. A CSV holds one table, so a dump with several tables asks which one to convert. It does not run SQL, read SELECT results, or connect to a database; the parsing happens in your browser.
Example
A mysqldump-style INSERT with three rows, an escaped quote, and a NULL, and the CSV the tool returns:
SQL
INSERT INTO `users` (`id`, `name`, `city`) VALUES (1, 'Ann', 'Paris'), (2, 'O\'Brien', NULL), (3, 'Smith, John', 'Lyon');
CSV
id,name,city 1,Ann,Paris 2,O'Brien, 3,"Smith, John",Lyon
How to convert SQL INSERT statements to CSV
- 1Paste SQL with INSERT statements into "SQL input".
- 2Click "Convert".
- 3If several tables are found, click the "Convert table" button that carries the table you want.
- 4Click "Copy", or "Download" to save the rows of that table as data.csv.
Formats and limits
- Input
- SQL text with INSERT INTO … VALUES statements
- Output
- CSV, header row from the column list (column_1, column_2… without one), file data.csv
- NULL
- empty field
- Tables
- one per CSV; you choose when there are several
Where your file is processed
The SQL is parsed by the page in your browser and is not uploaded; no database is involved. Errors are reported to us with the tool name and your browser version, and their text is cleaned of quoted parts, but the messages about several tables or mismatched column lists contain those table and column names.
Frequently asked questions
Does it read multi-row INSERT statements from mysqldump?
Yes. Every tuple of VALUES (…), (…), (…) becomes a row, across all the statements you paste. A MySQL escape such as O\'Brien and the standard O''Brien both come out as O'Brien.
Is NULL written as the word NULL?
No. NULL becomes an empty field, the same as an empty string, because CSV has no separate null. Search the SQL before converting if you need to tell the two apart.
Can statements list their columns differently?
No. All INSERT statements for a table must list the same columns in the same order; otherwise the tool stops and shows both lists, since the rows would not line up. Statements without any column list get the headers column_1, column_2, and so on.
Are function calls such as NOW() evaluated?
No. Nothing is executed: NOW() is written as the text NOW(). Backslash sequences other than an escaped quote are kept as written, because MySQL and standard SQL read them differently.
Tips and tricks
- ✓To create INSERT statements from a CSV file, use CSV to SQL.
Related tools
- CSV to SQL — the other way: CREATE TABLE and INSERT statements from a CSV.
- SQL Formatter — put each SQL keyword and column on its own line.
- CSV to Excel — open the resulting CSV as an .xlsx workbook.
- CSV to JSON