How do I backup and restore the database

data recovery

How to backup and restore database

There are a number of How do I backup and restore the database methods that can be used to backup and restore database. They include the use of the following tools;  

1. PHPMyAdmin

2. Compression of Data

3. Command Line

PHPMyAdmin tool 

This is the backup and restore tool that is commonly used due to its wide use among the service providers. 

Procedure for backing up database  

● Start phpMyAdmin.

● Browse your database list and choose your target database from the list presented in the left pane of your window. A menu of actions will then appear.

● From the menu, open the Export link.

● While the Export window is still open, select the tables you wish to back up.

● Then choose the Save to file option. Also ensure that this matches your preffered compression method.

● Click on ‘Go’ button and complete the wizard to save the file in your local machine.

Procedure for restoring Database using PHPMyAdmin tool  

● Start phpMyAdmin.

● Create a database and name it appropriately.

● Once you have successfully created it, browse the database lists on the left pane of the window, and select it.

● Once you have selected the database, a menu will appear.

● Open the IMPORT link on the menu. This will lead you to a new window that provides you with the capability to upload your previously saved SQL file. Use the browse button to locate the previously saved SQL file.

● Complete the wizard to complete the import process.

● Click on window’s Go button to execute the commands in the SQL file and finally restore it.

Backing up using Command Line 

This method is preferred when the database admin is highly experienced and has mastered the necessary commands to carry out the operation. This method requires telnet or shell access to the web server. 

The process of backing up the database is as shown below; 

Procedure for Backing up Database through command line  

● Open the shell.

● Type the backup command while observing its syntax, as follows;

$ mysqldump –opt -u database_username –p Databas_password Database_name > backup_file_name 

Restoring the database using command line 

Procedure  

● Start by creating a database in your target computer, and name it appropriately.

● Open the Mysql command window. This is where you will write your commands for restoring this database.

● $ mysql -u [database username] -p[Database password] [your target database] < [backup file name]

However, when restoring backup files that are in compressed form, you need to write the following command and the rest will be done for you in the background. 

gunzip < backup_file_name | mysql -u Your_database_username –p Your_database_password Your_database_ name 

It’s also important to note that you must know the name of your backup file plus its extension for the process of backup and restore to be a success.