Menu

Get data out of a .sql dump without restoring it
📰

Get data out of a .sql dump without restoring it

DEV Community: postgres·hammadrasool2000-svg·7 days ago
#7otfiSEP
#devtopostgresql#devto#dev#line#customers
Long article (1110 words) — no AI summary yet.
Reading 0:00
15s threshold

Someone sends you shop.sql and asks for "the customers in a spreadsheet". The usual advice is to install MySQL or PostgreSQL, restore the dump, then export. That is a lot of setup for one table.

You don't need any of it. A dump is a text file that already contains every row. You only need to know which of three formats you're looking at.

Step 1: look inside the file

Open it in any editor (or head -50 shop.sql ) and find the rows.

mysqldump writes multi-row INSERT s with no column names and backslash escapes:

CREATE TABLE `customers` ( `id` int NOT NULL AUTO_INCREMENT , `name` varchar ( 255 ) DEFAULT NULL , PRIMARY KEY ( `id` ) ) ENGINE = InnoDB ; INSERT INTO `customers` VALUES ( 1 , 'O\'Neil' ) , ( 2 , 'Sara \"S\"' ) ;

Enter fullscreen mode

Exit fullscreen mode

pg_dump (plain format) writes a COPY ... FROM stdin block: tab-separated, \N for NULL, ended by \. :

COPY public .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.