WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Backing Up Your Database

It is strongly recommended that you backup your database at regular intervals and before an upgrade.

Restoring your database from backup is then possible if something goes wrong.

NOTE: Below steps backup core WordPress database that include all your posts, pages and comments, but DO NOT backup the files and folders such as images, theme files on the server. For whole WordPress site backup, refer WordPress Backups.

Backup using cPanel X

cPanel is a popular control panel used by many web hosts. The backup feature can be used to backup your MySQL database. Do not generate a full backup, as these are strictly for archival purposes and cannot be restored via cPanel. Look for 'Download a MySQL Database Backup' and click the name of the database. A *.gz file will be downloaded to your local drive.

There is no need to unzip this file to restore it. Using the same cPanel program, browse to the gz file and upload it. Once the upload is complete, the bottom of the browser will indicate dump complete. If you are uploading to a new host, you will need to recreate the database user along with the matching password. If you change the password, make the corresponding change in the wp-config.php file.

Using phpMyAdmin

phpMyAdmin is the name of the program used to manipulate your database.

Information below has been tried and tested using phpMyAdmin version 4.4.13 connects to MySQL version 5.6.28 running on Linux.

phpMyAdmin Top

Quick backup process

When you backup all tables in the WordPress database without compression, you can use simple method. To restore this backup, your new database should not have any tables.

  1. Log into phpMyAdmin on your server
  2. From left side window, select your WordPress database. In this example, the name of database is "wp".
  3. The right side window will show you all the tables inside your WordPress database.
    Click the 'Export' tab on the top set of tabs.
  4. WordPress database view

  5. Ensure that the Quick option is selected, and click 'Go' and you should be prompted for a file to download. Save the file to your computer.
    Depending on the database size, this may take a few moments.
  6. Quick Export

    Custom backup process

    If you want to change default behavior, select Custom backup.

    1. In above Step 4, select Custom option. Detail options are displayed.
    2. Custom Export

    3. The Table section
    4. All the tables in the database are selected.
      • If you have other programs that use the database, then choose only those tables that correspond to your WordPress install. They will be the ones with that start with "wp_" or whatever 'table_prefix' you specified in your 'wp-config.php' file.
      • If you only have your WordPress blog installed, leave it as is (or click 'Select All' if you changed the selection)
    5. The Output section
    6. Select 'zipped' or 'gzipped' from Compression box to compress the data.

      Export Output section

    7. The Format section
    8. Ensure that the SQL is selected. Unlike CSV or other data formats, this option exports a sequence of SQL commands.

    9. The Format-specific options section
    10. Leave options as they are.

      phpMyAdmin Export Format Specific

    11. The Object creation options section
    12. Select Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement. Before table creation on target database, it will call DROP statement to delete the old existing table if exist.

      phpMyAdmin Export Object creation

    13. The Data creation options section
    14. Leave options as they are.

      phpMyAdmin Export Data creation

    15. Now click 'Go' at the bottom of window and you should be prompted for a file to download. Save the file to your computer.
      Depending on the database size, this may take a few moments.

    Remember - you have NOT backed up the files and folders - such as images - but all your posts and comments are now safe.

    Using Straight MySQL/MariaDB Commands

    phpMyAdmin cannot handle large databases so using straight MySQL/MariaDB code will help.

    1. Change your directory to the directory you want to export backup to:

    user@linux:~> cd files/blog
    user@linux:~/files/blog>
    

    2. Use mysqldump command with your MySQL server name, user name and database name. It prompts you to input password. (For help, try: man mysqldump.)

    To backup all database tables
    mysqldump --add-drop-table -h mysql_hostserver -u mysql_username -p mysql_databasename
    To backup only certain tables from the database
    mysqldump --add-drop-table -h mysql_hostserver -u mysql_username -p mysql_databasename mysql_tablename1 mysql_tablename2 mysql_tablename3

    Example:

    user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp > blog.bak.sql
    Enter password: (type password)
    

    3. Use bzip2 to compress the backup file

    user@linux:~/files/blog> bzip2 blog.bak.sql
    

    You can do the same thing that above two commands do in one line:

    user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | bzip2 -c > blog.bak.sql.bz2
    Enter password: (type password)
    

    The bzip2 -c after the | (pipe) means the backup is compressed on the fly, and the > blog.bak.sql.bz2 sends the bzip output to a file named blog.bak.sql.bz2.

    Despite bzip2 being able to compress most files more effectively than the older compression algorithms (.Z, .zip, .gz), it is considerably slower (compression and decompression). If you have a large database to backup, gzip is a faster option to use.

    user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | gzip > blog.bak.sql.gz
    

    Using MySQL Workbench

    MySQL Workbench (formerly known as My SQL Administrator) is a program for performing administrative operations, such as configuring your MySQL server, monitoring its status and performance, starting and stopping it, managing users and connections, performing backups, restoring backups and a number of other administrative tasks.

    You can perform most of those tasks using a command line interface such as that provided by mysqladmin or mysql, but MySQL Workbench is advantageous in the following respects:

    • Its graphical user interface makes it more intuitive to use.
    • It provides a better overview of the settings that are crucial for the performance, reliability, and security of your MySQL servers.
    • It displays performance indicators graphically, thus making it easier to determine and tune server settings.
    • It is available for Linux, Windows and MacOS X, and allows a remote client to backup the database across platforms. As long as you have access to the MySQL databases on the remote server, you can backup your data to wherever you have write access.
    • There is no limit to the size of the database to be backed up as there is with phpMyAdmin.

    Information below has been tried and tested using MySQL Workbench version 6.3.6 connects to MySQL version 5.6.28 running on Linux.

    MySQL Workbench Top

    Backing Up the Database

    This assumes you have already installed MySQL Workbench and set it up so that you can login to the MySQL Database Server either locally or remotely. Refer to the documentation that comes with the installation package of MySQL Workbench for your platform for installation instructions or online document.

    1. Launch the MySQL Workbench
    2. Click your database instance if it is displayed on the top page. Or, Click Database -> Connect Database from top menu, enter required information and Click OK.
    3. Click Data Export in left side window.
    4. Data Export

    5. Select your WordPress databases that you want to backup.
    6. Specify target directory on Export Options. You need write permissions in the directory to which you are writing the backup
    7. Click Start Export on the lower right of the window.

    Data Export selected database

    Restoring From a Backup

    1. Launch the MySQL Workbench
    2. Click your database instance if it is displayed on the top page. Or, Click Database -> Connect Database, and Click OK.
    3. Click Data Import/Restore in left side window.
    4. Specify folder where you have backup files. Click "..." at the right of Import from Dump Project Folder, select backup folder, and click Open
    5. Click Start Import on the lower right of the window. The database restore will commence.

    Data Import

    MySQL GUI Tools

    In addition to MySQL Workbench, there are many GUI tools that let you backup (export) your database.

    Name OS (Paid edition) OS (Free edition) Notes
    MySQL Workbench Windows/Mac/Linux Windows/Mac/Linux See above
    EMS SQL Management Studio for MySQL Windows -
    Aqua Data Studio Windows/Mac/Linux Windows/Mac/Linux (14 days trial) Available in 9 languages
    Navicat for MySQL Windows/Mac/Linux Windows/Mac/Linux (14 days trial) Available in 8 languages
    SQLyog Windows -
    Toad for MySQL - Windows
    HeidiSQL - Windows
    Sequel Pro - Mac CocoaMySQL successor
    Querious - Mac

    Database Backup Plugins

    Although command line tools such as mysqldump or established database management scripts such as phpMyAdmin or Adminer are generally considered most reliable when it comes to exporting a WordPress database, there are also various free plugins available that can export your database from within the WP Admin dashboard itself. These WordPress plugins can be used in case these other previously mentioned backup tools are not readily available, or for reasons of convenience.

    WP-DB-Backup

    WP-DB-Backup is maintained by Austin Matzko, based on code originally released by Skippy. It was in fact bundled with WordPress 2.0, but is no longer included as part of WordPress core (nor is any other backup tool).

    1. Search "WP-DB-Backup" on Administration > Plugins > Add New
    2. Click Install Now, then Activate
    3. Navigate to WP Admin > Tools > WP-DB-Backup
    4. Select which database tables to backup (core tables are always included)

    WordPress Database Backup plugin Tables section

    1. Select the backup destination, or schedule regular backups
    2. Finally, click Backup Now!

    WordPress Database Backup plugin Options section

    The file created is a standard SQL file that downloads to your local computer.

    WP Migrate DB

    WP Migrate DB is maintained by Delicious Brains and is a more advanced database export tool that can also run search/replace queries, and supports various compatibility and exclusion options during the export process.

    1. Search "WP Migrate DB" on Administration > Plugins > Add New
    2. Click Install Now, then Activate
    3. Navigate to WP Admin > Tools > Migrate DB
    4. Select the backup destination, and review advanced options
    5. Finally, click Export

    WP Database Backup

    WP Database Backup is maintained by Prashant Walke and supports database backup scheduling along with restoration of previous database snapshots, which are automatically saved on your WordPress server.

    1. Search "WP Database Backup" on Administration > Plugins > Add New
    2. Click Install Now, then Activate
    3. Navigate to WP Admin > Tools > WP-DB-Backup
    4. Select Create New Database Backup or choose Scheduler
    5. Review advanced options and email notification settings
    6. Finally, click Save Settings and/or then Download after backup is complete

    Export Database

    Export Database is maintained by LittleBizzy and is a simplistic database export tool that supports ZIP and Gzip.

    1. Search "Export Database" on Administration > Plugins > Add New
    2. Click Install Now, then Activate
    3. Navigate to WP Admin > Tools > Export DB
    4. Select compression options as desired (recommended)
    5. Finally, click Export

    All-in-One WP Migration

    All-in-One WP Migration is a quick, easy, and reliable database export tool. The plugin is maintained by ServMask.

    1. Search "database export" on Administration > Plugins > Add New
    2. Click Install Now, then Activate
    3. Navigate to WP Admin > All-in-One WP Migration > Export
    4. Click Export to File

    More Resources

    External Resources