How to Backup and Restore MySQL database!

       

 


 

        When we want to upgrade our various software in Linux based Ubuntu operating system then it is mendatory to back up the database. For example, the library system software KOHA, if we want to upgrade the ILS then we have to back up the old database and after the up-gradation of the KOHA we have to restore the database to get back all our data. Here, in this article, the process of back up and restoration of MySQL database given below -

 

Step - 1 : Login as Superuser

To log in as Superuser enter the below command in terminal -

sudo su

Enter system password


Step - 2 : Back up the Database

mysqldump -u username -p database_name > backup_name.sql

Here, in the above command, enter mysql user name in the place of username and target database name in the place of database_name and enter backup file name in the place of backup_name.

Example :

mysqldump -u root -p koha_library > kohabackup.sql

Here, root is the username, koha_library is the database and kohabackup is the backup file name.

It will create a backup file in the Home folder.

Restore the database

After upgrading the software it is needed to restore the database

 

Step - 3 :  Login to MySQL

To restore login to the mysql

Enter the below command

mysql -u user_name -p

Here, change user_name accordingly

 

Step - 4 : Create a Database

CREATE DATABASE database_name;

Here, enter your database name in the place of database_name

Then Type  

Exit;

 

Step - 5 : Restore the file

Connect dump file to the newly created database

mysql -u user_name -p database_name < Back-up_name.sql

Here, Change user_name, database_name and Back-up_name 

Example :  

mysql -u root -p koha_library < kohabackup.sql

It will take some time and all data now restored successfully. Good Luck!

 

No comments:

Popular Posts

Powered by Blogger.