Change WordPress Table Prefix [Before/After Installation]

We all knows that WordPress CMS is one of the favourite CMS for hackers. Hence it’s very important to change the default configuration such as Table Prefix name which is (wp_) as by default to something else which is very hard to judge, because the spammers/hackers knows about the default prefix table name which leads to various attacks like SQL Injection or Cross site scripting.

[Before Installation]

While installing WordPress, you can easily change the default Table Prefix name as shown in following screen.

[After Installation]

If you are planning to change the Database Table Prefix name after installation then you need to run some SQL queries directly from PHPMYADMIN and also need to edit the wp-config.php file.

By default, WordPress always creates around 12 tables with default prefix name which is wp_. Fortunately you can easily improve your website security by changing this table prefix name to something completely random and unique.

Default WordPress tables are wp_commentmeta, wp_comments, wp_links, wp_options, wp_postmeta, wp_posts, wp_termmeta, wp_terms, wp_term_relationships, wp_term_taxonomy, wp_usermeta and wp_users.

Step 1 – Make sure that you must put some kind of Under Maintenance Page so that visitors won’t able to see any kind of Error related to database. Also you should create a latest backup of your application before changing the database table prefix name.

Step 2 – Edit your wp-config.php file which contains some sensitive database information along with your table prefix name.

Change your database table prefix name from wp_ to something more secure like wp_ehrfierggleroh_ or something else as shown below

Step 3 – In this step, you need to open your PHPMYADMIN Panel and run the following queries to rename all the database table names from wp_ to wp_ehrfierggleroh_.

Here are the 12 SQL commands to rename all 12 default WP tables.

RENAME table `wp_commentmeta` TO `wp_ehrfierggleroh_commentmeta`;
RENAME table `wp_comments` TO `wp_ehrfierggleroh_comments`;
RENAME table `wp_links` TO `wp_ehrfierggleroh_links`;
RENAME table `wp_options` TO `wp_ehrfierggleroh_options`;
RENAME table `wp_postmeta` TO `wp_ehrfierggleroh_postmeta`;
RENAME table `wp_posts` TO `wp_ehrfierggleroh_posts`;
RENAME table `wp_termmeta` TO `wp_ehrfierggleroh_termmeta`;
RENAME table `wp_terms` TO `wp_ehrfierggleroh_terms`;
RENAME table `wp_term_relationships` TO `wp_ehrfierggleroh_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_ehrfierggleroh_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_ehrfierggleroh_usermeta`;
RENAME table `wp_users` TO `wp_ehrfierggleroh_users`;

Suppose if there are more WP tables created by some themes/plugins then you can run the same SQL query as per above syntax. The goal here is to rename all the tables that begins with default table prefix wp_.

Step 4 – Now search the options table for any instances of old prefix by run the following SQL query:

SELECT * FROM `wp_ehrfierggleroh_options` WHERE `option_name` LIKE ‘%wp_%’

As you can see that there are two entries which started by wp_ so change the wp_ to wp_ehrfierggleroh_ which looks like this:

Step 5 – Furthermore search the same for usermeta table by run the following query:

SELECT * FROM `wp_ehrfierggleroh_usermeta` WHERE `meta_key` LIKE ‘%wp_%’

Ideally at this point, all instances of the old table prefix (wp_) have been replaced with the new (wp_ehrfierggleroh_ in our case).

Once this is done, go check your site for proper functionality. Test all the pages, posts, search, admin login, and everything else you can think of (or have time for). If your site seems to be working as before, chances are good that the surgery was a success. Now make another database backup for good measure.

You may also like:

Sarcastic Writer

Step by step hacking tutorials about wireless cracking, kali linux, metasploit, ethical hacking, seo tips and tricks, malware analysis and scanning.

Related Posts