Skip to content

How to Extract Tables Backup from Full MySQL Dump File

How to Extract Tables Backup from Full MySQL Dump File. This tutorial will help you to extract single table or multiple tables from full mysqldump file

Steps
3
Category
Databases
Covers
MySQL
Versions & support
About MySQL →
On this page 3 steps

Mysqldump is an utility provided by MySQL/MariaDB to backup databases and tables. Generally, we take a full dump of database regularly and keep it. But some times we required to recover a single or 2-3 tables from backup. Then the question if how to restore a specific table from the full backup file. This article will help you to how to extract tables backup from the full database backup file. Also, we can extract all tables backup in individual files per table.

Step 1 of 3Download MySQL Dump Split Script

To split a full mysqldump database backup file in separate table specific files backup. Create a file named splitDB.sh and Copy below script in it.

This script taken from https://gist.github.com/jasny/1608062.

Step 2 of 3Extract All Tables from Dump

For this example I have a dump file named mydb.sql, which i want to split in small backups per table. For this I have created a new directory /opt/splitdb and copied above script with name splitDB.sh in this directory. Now use following command to extract all tables in individual backup files.

cd /opt/splitdb
chmod +x splitDB.sh
./splitDB.sh mydb.sql    #Do not run with 'sh' command 

Step 3 of 3Extract Single Table from Dump

If we want to extract only one table, We can use command like below. For example I want to split only table named my_tbl1 and my_tbl2. it will extract backup in current directory with name my_tbl1.sql and my_tbl2.sql.

cd /opt/splitdb
chmod +x splitDB.sh
sh splitDB.sh mydb.sql my_tbl1
sh splitDB.sh mydb.sql my_tbl2

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

5 Comments

  1. I’m Aman from CyberPanel. The Bash clarification in the discussion and Step 2 is helpful, but the two single-table commands in Step 3 still invoke sh. Making that section use the same intended interpreter would complete the correction and avoid sending readers back into the reported delimiter problem. I would also restore an extracted file into a temporary database before touching the live website: splitting a dump successfully does not itself verify a usable recovery set.

  2. with debian change:

    NAME=`head -n1 $FILE | cut -d$’x60′ -f2`

    to:

    NAME=`head -n1 $FILE | cut -d $(echo -e ‘\x60’) -f2`

    this worked for me …

  3. while running this script it show error
    splitdb.sh: line 14: ct_olts.sql: command not found
    cut: the delimiter must be a single character
    Try ‘cut –help’ for more information.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top