How to Change the WordPress Database Prefix to Improve Security
WordPress database seems to be the brain fo your full website. It is because every amount of information is available there and it can become the target of those people who want to get over your system. Spammers run automated codes for SQL injections. Unluckily, there are several website owners who do not change the database prefix while installing WordPress. It enables the bots to mass attack by targeting the defaul prefix that is, wp-admin. It is a smart move to protect the database of WordPress by changing its prefix which is an easy task while setting up your website. You need to follow few steps to change the WordPress database prefix in a proper way. In this way, you will not mess with your established website.
I suggest that you create a backup of your WordPress database before you act on anything I am going to suggest in this post. It is necessary to create a backup of your website on daily basis. BackupBuddy is a highly recommended plugin for this purpose. Next thing I suggest is that you redirect your visitors to a temporary maintenance page.
Change Table Prefix in wp-config.php
Open your wp-config.php file that is available in your WordPress root directory. Change the table prefix line from wp- to something else like wp-greenhat
So the line will look like this:
Note: You can only change it to letters, numbers, and underscores.
Change all Database Tables Name
You have to access your database using phpMyAdmin, then change the table names to one I specified in wp-config.php file. If you have cPanel WordPress hosting, you can find the phpMyAdmin link available in your cPanel. See the image:
There are 11 default WordPress tables available in total, therefore, to change them manually is a hard task.
Therefore, in order to make things fast, I have a SQL query that you can use.
You may have to add lines for other plugins because they may use their own tables in the database of WordPress. The idea is that you change all tables prefix to your desired one.
The Options Table
I have to search the options table for any other fields that is using wp- as a prefix, so we can change them. To make the process easy use this query:
It will return a plenty of results, you need to go one by one to change these lines.
Next, the need is to search the user meta for all fields that are using wp- as a prefix, so you can change it. Use this SQL query to perform this:
The number of entries may differ depends on how many plugins you are using. Simply change everything that has wp- to the new prefix.
Backup and Done
So you are up to test the website. If you have followed the above steps explained by me, it should be working fine. After doing so, you need to create a new backup of your website to stay on safe side.
Do not forget to share this post.
Arsalan Rauf is an entrepreneur, freelancer, creative writer, and also a fountainhead of Green Hat Expert. Additionally, he is also an eminent researcher of Blogging, SEO, Internet Marketing, Social Media, premium accounts tips and tricks, etc.