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](https://dbapostmortem.com/wp-content/uploads/2023/12/image-10.png)
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 :](https://dbapostmortem.com/wp-content/uploads/2023/12/image-11.png)
Now we will drop and see if we can restore all the contents.
![How to Restore Mysql Database and Tables :](https://dbapostmortem.com/wp-content/uploads/2023/12/drop-database-mysql-1024x557.jpg)
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](https://dbapostmortem.com/wp-content/uploads/2023/12/image-13.png)
![How to Restore Mysql Database and Tables](https://dbapostmortem.com/wp-content/uploads/2023/12/restore-database-mysql-1024x649.jpg)
![select from table mysql](https://dbapostmortem.com/wp-content/uploads/2023/12/image-15.png)
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 :](https://dbapostmortem.com/wp-content/uploads/2023/12/image-16.png)
For this, we will delete all the rows from the test1 table and will restore it from the dump.
![delete from table mysql](https://dbapostmortem.com/wp-content/uploads/2023/12/image-17.png)
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](https://dbapostmortem.com/wp-content/uploads/2023/12/image-18-1024x545.png)
![select from table mysql](https://dbapostmortem.com/wp-content/uploads/2023/12/image-19-1024x538.png)
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.
Pingback: How to take MySQL database and table Backup: mysqldump