Taking database backup is a highly essential and sensitive job. Many firms used to follow a systematic approach for taking backup in a periodic interval. Those backup files will be archived in a proper way for future reference or restoring purposes. There are various ways to backup WordPress Database.
In this tutorial, we are going to see how to backup the WordPress database manually or programmatically via plugins. Below listed item are the key methods for taking WordPress database backup.
Let us discuss these methods in detail in the coming sections. Previously, we have created a simple database backup client using PHP.
This method can be used if you have authentication keys to access the WordPress site cPanel. Login to the cPanel and navigate through Files->Backup.
The cPanel Backup option will allow the authenticated user to take full, partial backup of the site. This backup interface will list all the databased under Patial Backup->Download a MySQL Database Backup.
Choose your WordPress site database from the list of links. It will export a .gz file and it will be downloaded to the browser. This exported file will be in a compressed form which could be imported as it is for restoring the database.
The database clients like PhpMyAdmin, SQLYog supports various database related operations like import, export and more. In this section, we will see the available options and customization allowed by the PhpMyAdmin application.
Visit PhpMyAdmin URL and login to it. Select the WordPress database among the list of databases. After selecting the database click the Export action tab which will exist on the PhpMyAdmin web interface.
By clicking the Export tab, the database client will show Quick and Custom radio options. By selecting the Quick option, the backup file will be exported with the complete database structure, data by default. By selecting the custom option, we can customize the settings to tell the specification to the client to take backup.
Database backup could be done via command line programming. In this heading, we will see the command to export the database to a .sql file. Also, we will see to create a compressed version of the database export using command line.
Before that, add the MySQL connector location to the system classpath to run the MySQL command in the command prompt.
Command to Export .sql via Command line
mysqldump -u [userName] -p [databaseName] > [database_name.sql]
Replace the [userName] and [databaseName] with your WordPress database username and DB name respectively. This command will write the .sql file as the complete backup of the database. We can also specify particular tables instead of exporting the complete database.
Command to Export .gz (compressed) file via Command line
mysqldump -u [userName] -p [databaseName] | gzip > [compressed_database_name.sql.gz]
This command will write the compressed form of database backup file. As specified in the command the file will be in .gz format as we have downloaded via cPanel interface.
Note: Both of the above commands will require the database password before writing the WordPress database backup.
There are many plugins available to add the feature to backup Database via WordPress admin. Some of those plugins are All-in-One WP Migration, WP Database Backup, WP-DB-Backup and more.
In this article, I have added the screenshot of All-in-One WP Migration plugin settings to take the WordPress database backup. Once installing and activating this plugin, the database backup configuration and export can be done via WordPress admin panel. If you are new to WordPress and want to see how to install a WordPress plugin, the linked beginner article will be useful.