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.
We have already taken backup test.sql through mysqldump utility which is the backup of the test database.
Now we will drop and see if we can restore all the contents.
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
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.
For this, we will delete all the rows from the test1 table and will restore it from the dump.
Now use the below syntax and load it from the test1.sql dump file
Syntax :
mysql -u root -p db_name< table_backup.sql
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