How to Change the Database of Your WordPress Site

HomeWordPressHow to Change the Database of Your WordPress Site

How to Change the Database of Your WordPress Site

In the WordPress system, database stores data like links, usernames, comments and so on. Without a database, your WordPress site won’t work. Backing up your WordPress database — as well as the files, of course — is strongly recommended. At least once a month. You never know what is going to happen to your website in the future. If your website got hacked and you have no backup file of it, then you will lose your site forever.

Speaking of hacking, not everyone is lucky enough to get their site back to normal after the hacking event. Even if you successfully make your site back to normal, you will not really safe. One of the steps you can take to rescue your website is to change the database. By changing your database, the hacker at least doesn’t know the database password anymore.

Whatever your reason for changing your WordPress database, whether regarding the hacking or not, here is how to change the database of your WordPress site.

Step 1: Export the current database

The first step you need to do before changing your WordPress database is to export the current database. No, you will not reuse this database. You just need the tables on this database, which you will export on the second step below. If you have no idea the database name your WordPress site, you can open the wp-config.php file.

You can use phpMyAdmin to export your database. Nearly all web hosting control panels, including cPanel and free cPanel alternatives like CentOS Web Panel and Webmin, already have this feature. Select your database on the left panel and click the Export tab to export your database. Make sure to export the database in the SQL format.

Step 2: Create a new database and import the tables

Once you are done exporting the current database, create a new database to host all of the tables you will import later. Look for the menu to create a new database on your control panel. If you use cPanel, you can click the MySQL Databases menu to create a new database.

Make sure to use a different password and username. Once done, go to phpMyAdmin to import the tables from the database you have exported on the step one above. To do so, select your new database on the left panel. Click the Import tab, select the database file you want to import the tables from, and click the Go button.

Step 3: Update the wp-config.php file

Lastly, you need to update the wp-config.php to connect your WordPress to the new database you have just created. You can either edit this file locally by downloading it first and re-upload again once you have edited it, or directly via the editor on your control panel. The part you need changes are: database name (DB_Name), database username (DB_USER), and database password (DB_PASSWORD).

Done, you can now delete your old database.

hand-picked weekly content in your inbox


related posts