How to convert SQL to CSV
Updated · 3 min read
Sometimes all you have is a .sql dump — from a backup, a WordPress export or a colleague — and you just need the rows in a spreadsheet. This converter reads INSERT INTO … VALUES statements, including multi-row inserts produced by mysqldump and pg_dump --inserts, and turns them into CSV without needing a database server.
- Paste the INSERT statements or drop a
.sqlfile. - Column names are read from the INSERT column list; without one, columns are named
column_1,column_2… - Check the row and column counts below the editors.
- Download the CSV, or switch the target to Excel or JSON.
Example
SQL input
INSERT INTO `customers` (`id`, `name`, `city`, `created_at`) VALUES
(1, 'Fatima Zahra', 'Fes', '2026-01-15 10:20:00'),
(2, 'John O\'Connor', 'Dublin', NULL),
(3, 'Lee, Min-jun', 'Seoul', '2026-03-02 08:05:41');CSV output
id,name,city,created_at
1,Fatima Zahra,Fes,2026-01-15 10:20:00
2,John O'Connor,Dublin,
3,"Lee, Min-jun",Seoul,2026-03-02 08:05:41The MySQL-style escaped quote in O\'Connor is decoded, the comma inside Lee, Min-jun is quoted in the CSV, and NULL becomes an empty cell.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
What the parser understands
- Single-row and multi-row
INSERT INTO … VALUES (…), (…);statements, as many as you like. - Column lists with backticks, double quotes or square brackets.
- Strings with doubled quotes (
'') or backslash escapes (\'), andN'…'/E'…'prefixes. NULL,TRUE/FALSEand numbers; function calls such asNOW()are kept as text.- Everything else in a dump —
CREATE TABLE,SET, comments — is ignored.
One table at a time
A full database dump contains inserts for many tables. Because a CSV file holds a single table, rows from all INSERT statements are combined. Paste the statements for one table at a time — in most dumps they are grouped under a comment such as -- Dumping data for table `customers`.
If you have database access
When the database is running, exporting with a query is faster and avoids parsing altogether — see the commands below. The converter is most useful when you only have the dump file, or when you cannot install database tools.
Convert SQL to CSV in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Export directly from the database
# MySQL / MariaDB (tab-separated)
mysql -u user -p -D mydb --batch -e "SELECT * FROM customers" > customers.tsv
# PostgreSQL
psql -d mydb -c "\copy (SELECT * FROM customers) TO 'customers.csv' WITH (FORMAT csv, HEADER true)"
# SQLite
sqlite3 -header -csv app.db "SELECT * FROM customers;" > customers.csv
Frequently asked questions
Does it support mysqldump and pg_dump files?
Yes, as long as the data is written as INSERT statements (pg_dump needs the --inserts or --column-inserts option; its default COPY format is already tab-separated text).
What if my INSERT has no column list?
The columns are named column_1, column_2 and so on. Rename them in the CSV header or add the column list to the statement.
Are NULL values preserved?
In CSV, NULL becomes an empty cell. Convert to JSON instead if you need to distinguish NULL from empty strings.
Can I convert to Excel directly?
Yes. Choose Excel as the target format and download an .xlsx file.
Is my dump uploaded?
No. It is parsed in your browser — useful for dumps that contain personal data.