
Restoring a single database from a full MySQL database dump can save time and resources when you only need specific data. Whether you're recovering a WordPress site or managing multiple databases, this process ensures you extract and restore only the required database without affecting the rest of the dump.
MySQL Dump is a backup utility used to recover your databases and tables in case your database server crashes. A single MySQL Database Dump is a logical backup in a flat file with Standard Query Language (SQL) statements that restore a database to its original state before backup.
MySQL dump files are important when transferring databases from one server to another or when recovering the database server from a crash. This guide illustrates how you can restore a single database from a full MySQL database dump consisting of two or more databases.
Before you start, make sure you:
To create a Full MySQL database dump, make sure you have two or more databases available on your database server. For purposes of this guide, create three new databases on your server as below.
Log in to the MySQL console.
Create the databases.
Switch to the db1 database.
Add a new table to the database.
Create a new privileged user.
Grant the user full privileges to all databases.
Reload MySQL privileges.
Exit the console.
Create a full MySQL dump of all databases.
A new backup.dump file is added to your working directory.
For restoration purposes, re-login to the MySQL console.
Delete the databases you created earlier.
Exit the MySQL console.
To restore a single database from a full MySQL dump, you should create an empty database with the same name, then restore the single database to recover all its tables and table data. For this guide, restore the db1 database as below.
Verify that the full MySQL dump file exists in your working directory.
Output:
Restore the db1 database from the full MySQL dump to a new file without importing it to the database server.
Import the single database file to the database server.
When the command completes, re-login to the MySQL console to verify changes.
Switch to the db1 database.
Show all tables to verify that your data is available.
Output:
Exit the MySQL console, and restore any other databases.
Back up the example table from the db1 database using the following command.
Assuming you want to restore the example-tbl.sql file to a new database such as db2, run the following command.
Login to the MySQL console.
Switch to the db2 database.
Verify that the example table is available.
Exit the console.
You can back up database tables and restore them to any other databases without any restriction on the source database name.
You have restored a single database from a full MySQL Database dump on your database server. You can automate periodic MySQL backups and restore them to a new server or in case the database server crashes. For more information, please visit the following resources.
0 Comments
Be the first to comment and share your perspective with the community.