Extracting a Table from a MySQL Dump
Occasionally, I need to use the data in a single table from a full MySQL database backup dump. Ordinarily, you’d just import the database dump into MySQL and go. Unfortunately, if the dump file is several Gigabytes (even when compressed), it becomes time-consuming to SCP this file around and then load it into MySQL.
In order to speed up the process, I extract the table I need from the full database dump. Then, I can take that table, SCP it to where I need it, load it into MySQL, and perform necessary operations with it. Fortunately, complicated programs and commands are not necessary for this: only
grep
and sed
are needed.
The first step is to determine the table structure from the decompressed MySQL database dump:
BASH
- Example:
Let’s say we want to extract thephpbb_config
table from a giant MySQL phpBB database dump.
BASH
- This will provide you with the starting line number in the MySQL dump file which defines each table. Using this, determine the starting and ending line numbers of the table you need (the ending line number will be the starting line number of the next table, minus one).
The next step is to actually extract the table from the MySQL database dump file:
BASH
- Example:
I extract thephpbb_config
table intotmp.sql
, and then usehead
to check that the SQL in the file is what I am expecting.
BASH
The last remaining step is to use the extracted table:
BASH
- Example: Now I load the
phpbb_config
table into a temporary MySQL database.
BASH
Note that these steps presume a decompressed, full MySQL database dump which contains table
DROP
, CREATE
, and INSERT
SQL.
Tidak ada komentar:
Posting Komentar