Change Your WordPress Database Name in 3 Simple Steps
Your WordPress database holds all of your site’s important information, so keeping it safe and organized isn’t something that should be neglected.
Naming your database in a descriptive way can help you more easily keep track of your site and help prevent you from making unintended changes when you can’t tell your databases apart. It also helps protect your site by making it more difficult for hackers to identify and access your database details.
It’s easy to change your database from a default name like db_wordpress123 to db_mysite and it can be done in about five minutes. In this Weekend WordPress Project, I’ll show you how to change the end of your database name to something more recognizable to you, while also being less guessable for hackers.
Edit Your Database
Head over to phpMyAdmin. In cPanel, you can access it through the Databases section of the home page. Once there, select your database from the menu on the left, then click the Operations tab at the top.
Under Rename database to, enter the name you would like to see for your database in the text field and click Go on the bottom, right corner of field. You will be prompted with a pop-up to accept the change.
You will be creating a new database with your chosen name, dropping the tables in your original, then importing those tables to your new database. Click OK to continue with these changes.
Edit Your wp-config.php File
Navigate to your site’s files and in the root of your WordPress install, locate your wp-config.php file. In cPanel, edit the file by selecting it from the list and clicking the Edit button at the top of the page. If a pop-up appears, click Edit again.
You can also choose to download the file through FTP and edit it with a text editor. Either way, include your new database name by finding the piece of code similar to the one below:
define('DB_NAME', 'your_db'); in your file, where
your_db is the original name of your database and change it to the new name you chose a moment ago.
Save the file and if you’re using FTP, upload the new file to the root of your install.
Assign a Database User
In cPanel, click on MySQL Databases under the Databases section. Scroll down to the Add a User to a Database area and select your username from the User drop down box.
If you’re not sure what it is, it’s listed in your wp-config.php file on the line with
DB_USER just like in the example above.
Next, select your new database name from the Database drop down box and finally, click the Add button. On the page that loads, select the All Privileges checkbox toward the top, then click the Make Changes button below the table.
Reactivate all your plugins and you’re done!
Go ahead and visit your site. It should be up and running with your new database name. Now you’ll be a bit more organized and safer.
If you’re interested in making more customizations to your database, check out our post Creating Custom Database Tables for Your WordPress Plugins.
If you’d like more ways to secure your site, check out our posts WordPress Security Essentials: Say Goodbye to Hackers, WordPress Security Essentials : Four Points Of Vulnerability and WordPress Security Essentials: Obscurity Tactics and Backups.
There are other ways to change your database name, but I find this one the easiest. What’s your preferred method? Feel free to share your thoughts in the comments below.