How to Restore Mysql Database and Tables :

In our previous article, we have already seen how to take a backup of MySQL databases and tables. So today we will learn about how to restore MySQL database and tables. Without backup, it is not possible to restore, so backup is the most important thing for restoring. Let’s go through the steps :

Restore a Mysql Database :

So here we want to drop test database and restore it from backup. We can see there is a table test1 inside the database and there are 4 rows under the table.

show database mysql

How to Restore Mysql Database and Tables :

We have already taken backup test.sql through mysqldump utility which is the backup of the test database.

How to Restore Mysql Database and Tables :

Now we will drop and see if we can restore all the contents.

How to Restore Mysql Database and Tables :

To restore it, load the dump file using the below command. Before that, create a blank database to load the dump file into it, else you will get an error.

Syntax :
mysql -u root -p db_name < db_name.sql
create database mysql
How to Restore Mysql Database and Tables
select from table mysql

Restore a table in MySQL :

Now we will see how to restore a table in MySQL database. So a sql file has been already created for the table backup (test1.sql) for this.

How to Restore Mysql Database and Tables :

For this, we will delete all the rows from the test1 table and will restore it from the dump.

delete from table mysql

Now use the below syntax and load it from the test1.sql dump file

Syntax :
mysql -u root -p db_name< table_backup.sql
Restore Mysql Database and Tables
select from table mysql

So here is the simple method how to restore MySQL database and tables. Hope it helps!!

Also you can follow the Percona documentation for MySQL restoration table and databases.

This Post Has One Comment

Leave a Reply