Exporting your database (database backup)

There are multiple ways to export a database. You can either use phpMyAdmin or SSH commands. If you are not familiar with terminal commands we recommend you stick to the phpMyAdmin way. 

Exporting Databases Through phpMyAdmin

To export your database through phpMyAdmin, you first have to login to phpMyAdmin. Before exporting your database, make sure you are on the correct database, and not information_schema. When you have clicked on the database you want to export you can easily go to the export tab and click finish. This will save the database dump locally on your computer.

Exporting Databases with Command Line Tools

For exporting your database through terminal, you need to access the server through SSH. Once you have accessed the server you insert your information into this command:

mysqldump --single-transaction -u USERNAME -p DATABASENAME > FILENAME.sql

If you want to go a step further to gzip your sql file you can run this command:

mysqldump --single-transaction -u USERNAME -p DATABASENAME | gzip > db_dump.sql.gz

To extract your gzipped sql file you can run this command: gunzip db_dump.sql.gz

After filling in your information, you are asked to enter the database password. After filling in the correct password, the server will process the information and create a database dump in your current directory. 

If you want to transfer this database dump to you local machine or to another server, you can do this through the rsync command or through FileZilla

Exporting Databases with WP-CLI (command line for WordPress)

If you have a WordPress site you can use this WP-CLI command in your WordPress directory (normally ~/public/):

Export the database

Login to the server using your SSH user and run command:

cd ~/public/ && wp db export ~/private/backup.sql

This is the the easiest way to backup the database of a WordPress site.

Restore the database (optional)

To restore the manual database backup, login using SSH and run command:

cd ~/public/ && wp db import ~/private/backup.sql

This requires that the database backup was created using the name backup.sql. Once the restoration is done, you’ll see a confirmation of the import process.

Give us your feedback on this article