Backup a MySQL Database with mysqldump

First of all, you need to have SSH access to the server to perform backup/restore database commands below:

Backup mysql database:

  1. Use this command line:
mysqldump -uusername -p database_to_backup > backup_name.sql
  • Username: DB authenticated username
  • database_to_backup: DB name
  1. Enter password for the username if asked.
  2. Wait until the backing up process is done.

Restore mysql database:

  1. Login to mysql and create a new database if you have not created one
mysql -u username -p
  1. Create new database and username/password if needed:
CREATE DATABASE database_name;
GRANT ALL ON database_name.* TO 'database_username' IDENTIFIED BY 'database_password';
  1. Import Mysql dump file:
mysql -udatabase_username -pdatabase_password database_name < backup_mysql_dump_file.sql
  1. Wait until the restoring process is done.

Written on 08 April 2018

Share your thoughts