Tuesday, February 12, 2019

How to Restore MySQL Database Dump in MySQL Server in Linux Box

In this article I would like to discuss how to Restore database dump into MySQL Server...

For our discussion, let me have the database dump of database "mysql" from MySQL Server, which I have already taken in a file named "serverdump-of-database-mysql.sql"

To know how to dump a database from MySQL server, you can checkout my article given below...
How to take MySQL dump using the command utility "mysqldump"
This article assumes you have the Username and Password handy to connect to database server.

I am going to use the root user's credentials to access the server instance and to have the database dump.

To try out I am going to assume the following properties
DATABASE : mysql_dump
USERNAME : root
PASSWORD : admin

Open up a terminal and connect to MySQL Sever as dictated below.
> mysql --user=root --password
The above command would prompt to provide the password, please provide the one you used to connect to server, I am going to use the password "admin" as mentioned above.

Soon after you provide the password, you would have mysql prompt as given in the image below...


Now create a database as given below...
mysql> create database mysql_dump;
The above statement creates a database named "mysql_dump", to check that use the statement below...
mysql> show databases;
The above statement would list down the databases like the one given below along with the one just created...

As you can see we have the database "mysql_dump" created with no tables in it... this can be justified by firing the following statement at the prompt
mysql> use mysql_dump;
mysql> show tables;

the above command results something like the image given below...


Now exit from MySQL Server by typing "exit" at the prompt.
mysql> exit
So far we had been working on the set up, now is the time to restore the database we had backed up.

To achieve that... type the following command at the prompt
> mysql --user=root --password mysql_dump < <location-of-the-dump-file>
eg
> mysql --user=root --password mysql_dump < /home/ravaneswaran/serverdump-of-database-mysql.sql
provide the password to restore the database.

To check the restoration process successful... connect to database server and check the database "mysql_dump", which can be done as follows...
> mysql --user=root  mysql_dump --password
provide the password...
mysql> show tables;

The response of the above statement would be as follows...




Well this concludes the restoration of backed up database in MySQL Server.

Hope you enjoyed reading.

No comments:

Post a Comment

How to change the root password in linux when it is forgotten/to change

This blog is all about changing the root password of the Linux system when it is forgotten or to reset the password...   Let's get it ...