How to Change the Database Name in WordPress
Posted onWordPress is filled with little tweaks that can significantly harden your installation. For example, you can change the name of your login and admin pages so that bots won’t be able to mindlessly spam them with login credentials. The default settings of WordPress and those of certain hosts are predictable and this gives a wide leeway to hackers who have a ready made architecture and naming convention at their fingertips. Yet another example is the default naming convention for your WordPress databases. Not only are they predictable, you yourself might find them confusing when you have several WordPress installations on the same host. Let’s take a look at how to change the database name in order to make it more meaningful.
Take a look at these two example databases on my current shared hosting account.
Merely by looking at them I’m unable to tell which belongs to which blog. For example, if I need to export the data of one of my blogs in SQL format, I need to either check the login information from my wp-config.php file, or open up the database and check the structure in search of telltale plug-ins that are unique to that site. Wouldn’t it be easier, if each blog had its own unique database name? Fortunately, making such a change is simple and only requires modifications in two places.
Making the Change in phpMyAdmin
We first need to access the database and change its name internally. You could of course use a remote MySQL client to do the job, but why bother when most shared hosting accounts provide you with easy web access using phpMyAdmin? Log into your shared hosting account and in cPanel, locate the phpMyAdmin icon as illustrated in this previous tutorial.
Once you’ve logged in, you can see all of your databases on the left-hand side as shown in the first screenshot. At least this once, you need to figure out which is which and click on the database instance belonging to the blog that we’re interested in. The right-hand pane will change and present you with a number of tabs along the top. To modify the name, we need to click the “Operations” tab as shown below:
As you can see, you will be presented with three dialog boxes out of which the middle one has a provision for changing the name of the current database. Type in a meaningful and easily identifiable name and click “Go”. This will execute an SQL query to change the database name. At this point, your backend database has a new name but it hasn’t been reflected in wp-config.php. As a result, your WordPress site would have broken and we need to quickly make the change in the configuration file!
Changing wp-config.php
Open up your blog’s root directory either using an FTP program like FireFTP for Firefox or your web host’s inbuilt directory browser.
Copy wp-config.php onto your PC download location and open it up using a plain text editor. Scroll down till you find the line starting with:
define('DB_NAME'
This will be followed by your own database name within single quotation marks. As shown in the screenshot below, replace it with the new name you have chosen, save it and copy the modified wp-config.php file back into your WordPress root directory.
Make sure you rename the old one to something like wp-config-backup.php just in case something goes wrong and you need to quickly revert back to the old version.
That’s it! These two simple changes will automatically give your WordPress database a new name thereby securing it from hackers as well as making management a bit easier. This will be a lot safer if you were to perform this on a test site first before making the changes to a live blog. Messing around with database structures is incredibly dangerous if you don’t know what you’re doing and you will want to get some experience first before going in for the real thing.