This brief tutorial is going to show you how to backup your WordPress database before upgrading and restore it if something goes wrong.

This post is part of our WordPress series which shows you how to install and manage a WordPress blog or website.

To read our previous WordPress’ tutorials, please click here, here and here.

In most cases, it’s recommended to backup WordPress’ database before upgrading WordPress. Now, you don’t have to do it, but it’s the right thing to do before upgrading. If you have access to your server via SSH, then this tutorial is applicable to you. If not, then you must use other methods of backing up and restoring your database, like using phpMyAdmin.


  • Backup WordPress’ Database Before Upgrading
  • Restore WordPress’ Database After Upgrading
  • Enjoy!

To get started, logon to your webserver via SSH. Then run the commands below to update your database.

mysqldump -u root -p database_name >> database_name.sql



Replace the database name with the name of your WordPress’ database.


If something goes wrong and you wish to restore your database, run the the commands below to logon to your MySQL server.

mysql -u root –p


After logging on, run the commands below to delete the current WordPress’ database. Since the current database is no longer valid, you must delete it.

drop database database_name;



Replace database_name with your WordPress’ database.


After deleting your current database, create an empty database with the same name by running the commands below.

create database database_name;


After creating an empty database, exit MySQL, then run the commands below to restore your database from the backed-up file.

mysql -u root -p database_name < database_name.sql



Replace database_name with your database.


That’s it!