How to Change the WordPress Database Prefix for Improve Security

WordPress Database is one of the most important thing for your entire WordPress site because every information of your site like content, theme setting, plugin etc are stored in there &it act like a for WordPress Website. Due to high importance of Databse in WP it is hacker’s favorite target and they attack by running automated codes like SQL injection.

Don’t worry, WordPress developers team are very familiar with all thses things and allow us to choose dabatase table prefix during the WP installation. Well, unfortunately many people forget to change the database prefix while installing WordPress and leave it as by default wp_. This makes it easier for hackers to plan a mass attack by targeting the default prefix wp_.

wordpress db prefix change step by step help
wordpress db prefix change step by step help

The smartest way you can protect your database is by changing the database table prefix which is very easy to do on a site that are already running.

To properly change the WP database table prefix you need to follow bellowing few steps.

Before you going to change the WP database prefix according to my article We recommend that you please backup your WordPress Database for Safety. One more thing we suggest you that for temporary set maintenance page for you Website visitors.

Change Table Prefix in wp-config.php

Open wp-config.php file which is located in your WordPress site root directory. Find $table_prefix and Change the default value from wp_ to something else like this wp_apl1234_ (Combination of numbers, letters and underscore, Don’t use special character)

So the line would look like this:
$table_prefix = ‘wp_apl1234_’;

Change Database All Tables Name

Now You need to update your existing dabase table prefix that are with by default wordpress wp_ prefix. To change table prefix you need to open your database and then update the table names prefix to the one that we specified in wp-config.php file.

In WordPress Database, There are total 11 default WordPress tables, so changing them one by one manually  would be painfully.

Execute below SQL Query with first replace wp_apl1234 with your choice WP table prefix that you have specified in wp-config.php

That’s why to make things faster, we have a SQL query that you can use.

RENAME table `wp_commentmeta` TO `wp_apl1234_commentmeta`;
RENAME table `wp_comments` TO `wp_apl1234_comments`;

RENAME table `wp_links` TO `wp_apl1234_links`;
RENAME table `wp_options` TO `wp_apl1234_options`;

RENAME table `wp_postmeta` TO `wp_apl1234_postmeta`;
RENAME table `wp_posts` TO `wp_apl1234_posts`;

RENAME table `wp_terms` TO `wp_apl1234_terms`;
RENAME table `wp_term_relationships` TO `wp_apl1234_term_relationships`;

RENAME table `wp_term_taxonomy` TO `wp_apl1234_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_apl1234_usermeta`;

RENAME table `wp_users` TO `wp_apl1234_users`;

If You have more tables that are used by Plugin than you need to update their prefix as you done for 11 tables.

Find & Update DB Tables value that store with old Prefix

To check all tables value that either store with old prefix. use Dabase search option, enter old Database prefix in search textbox, select all tables and press Go button, look at search result, This will return a number of found entries, Just change everything that has wp_ to the new prefix.

Finally Done, Test your website by removing temporary maintenance page that set before starting,  everything should be working fine if you followed all the above steps.

Leave a Comment

Scroll to Top