Databases

How to Backup and Restore Database in Linux

restore database
How to backup and restore MySQL databases

Backup and Restore Database in Linux

You can use “mysql” and “mysqldump” utility to backup and restore database in Linux. The mysqldump command is used to create a text file backup of databases. You can easily restore the database from this dump file using “mysql” command.

Backup MySQL database:

Syntax:

mysqldump -u [uname] -p[pass] [DBname] > [backupname.sql]
  • [uname] Your database username
  • [pass] The password for your database (No space between -p and the password)
  • [DBname] Database name
  • [backupname.sql] Database backup file name

Backup a Single Database:

mysqldump -u root -pmysqlrootpasswd database_name > database_name.sql

Replace the database_name with your desired dabase name and database_name.sql with your desired backup file name.

Multiple databases can be backed up at the same time:

mysqldump -u root -pmysqlrootpasswd --databases database_one database_two > databases.sql

Also, you can backup all databases on the server using the following command:

mysqldump -u root -pmysqlrootpasswd --all-databases > all_databases.sql

Restore MySQL database:

Syntax:

mysql -u [uname] -p[pass] [DBname] < [backupname.sql]
  • [uname] Your database username
  • [pass] The password for your database (No space between -p and the password)
  • [DBname] Database name
  • [backupname.sql] Database backup file name

Restore a Single Database:

mysql -u root -pmysqlrootpasswd database_name < database_name.sql

Replace the database_name with your desired database name and database_name.sql with your desired backup file name.

You can also restore a single database from the multiple database dump file:

mysql -u root -pmysqlrootpasswd --one-database database_name < all_databases.sql

Note: You can avoid using the username and password part (-u root -pmysqlrootpasswd) from the above mysql and mysqldump commands if you are using cPanel.

That’s it!

Read More: How to Backup and Restore Plesk Database

If you like this post and wish to receive more articles from us, please like our FB page: Button

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com

2 Comments

Click here to post a comment

Topics