How to Change Database Table Prefix in WordPress

,



Many people feel that WordPress is just bad when it comes to security. Over the years, WordPress has grown in popularity with millions of websites using it. Therefore, it has become a favorite target for most of the attackers and hackers who develop malicious and automated scripts to nuke websites with bots in order to hack a website, publish spam comments, or do SQL injection.



When you install WordPress, it creates tables in the database with the wp_ prefix.

Before making any changes to your website, make sure you’ve created a backup.

Changing Database Prefix Manually

Step 1: Editing wp-config.php

Access the root directory of your WordPress installation through an FTP software like FileZilla, find and edit the wp-config.php file using any code editor of your choice.



In the wp-config.php file, find the line that reads $table_prefix = ‘wp_’ and replace the wp_ with wc_ (or whatever prefix you prefer).



Save the file and upload it to the root of your WordPress installation.

Step 2: Renaming the Database Tables Using SQL Query

By default, WordPress creates tables with prefix wp_ in MySQL database that we connect to it. There may be more tables with wp_ prefix if you have a plugin that requires its own table.

The fastest way to change the database names is to change by running SQL queries. Run the SQL command from your MySQL Manager and use the following commands to make the change

RENAME table `wp_commentmeta` TO `wc_commentmeta`;
RENAME table `wp_comments` TO `wc_comments`;
RENAME table `wp_links` TO `wc_links`;
RENAME table `wp_options` TO `wc_options`;
RENAME table `wp_postmeta` TO `wc_postmeta`;
RENAME table `wp_posts` TO `wc_posts`;
RENAME table `wp_termmeta` TO `wc_termmeta`;
RENAME table `wp_terms` TO `wc_terms`;
RENAME table `wp_term_relationships` TO `wc_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wc_term_taxonomy`;
RENAME table `wp_usermeta` TO `wc_usermeta`;
RENAME table `wp_users` TO `wc_users`;


Step 3: Renaming the wp_ fields in Database Table

Apart from tables, there are two fields (wc_options and wc_usermeta in our case) by default that has field name beginning with wp_.

By using the following queries, we can change the prefix of those fields containing a wp_ prefix.

UPDATE `wc_options` SET `option_name`=REPLACE(`option_name`,'wp_','wc_') WHERE `option_name` LIKE '%wp_%';
UPDATE `wc_usermeta` SET `meta_key`=REPLACE(`meta_key`,'wp_','wc_') WHERE `meta_key` LIKE '%wp_%';




Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.