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.
Preparation
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:
1
|
$table_prefix = 'wp_a123456_' ; |
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.
1
2
3
4
5
6
7
8
9
10
11
12
|
RENAME table `wp_commentmeta` TO `wp_a123456_commentmeta`; RENAME table `wp_comments` TO `wp_a123456_comments`; RENAME table `wp_links` TO `wp_a123456_links`; RENAME table `wp_options` TO `wp_a123456_options`; RENAME table `wp_postmeta` TO `wp_a123456_postmeta`; RENAME table `wp_posts` TO `wp_a123456_posts`; RENAME table `wp_terms` TO `wp_a123456_terms`; RENAME table `wp_termmeta` TO `wp_a123456_termmeta`; RENAME table `wp_term_relationships` TO `wp_a123456_term_relationships`; RENAME table `wp_term_taxonomy` TO `wp_a123456_term_taxonomy`; RENAME table `wp_usermeta` TO `wp_a123456_usermeta`; RENAME table `wp_users` TO `wp_a123456_users`; |
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:
1
|
SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE '%wp_%' |
It will return a plenty of results, you need to go one by one to change these lines.
UserMeta Table
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:
1
|
SELECT * FROM `wp_a123456_usermeta` WHERE `meta_key` LIKE '%wp_%' |
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, codes, links, tips and tricks, etc.