Steps to Change WordPress Table Prefix to Improve Security

WordPress database is used to collect anything important of your website, including plugins, themes, and posts, which is just like a core of a WP site. Once completing WordPress installation, the database is created automatically and that includes a list of tables with the default prefix “wp_”.

Most users leave it to the default and never change it. As a matter of fact, you need to change the WordPress database table prefix. Because, WordPress security is an important matter for any blogger who wants to keep his site safe from hackers, malware, and cyber-attacks. The hackers know about the default WordPress table prefix which is a potential security risk. They specifically look for the wp_options table, because it will alter your WordPress site look. In this article, I will show you how to secure WordPress sites from attackers.

Through wp_options they can set the URL to redirect to their sites, leaving you the impression that your site was defaced. Therefore, it is better to change the default table prefix in WordPress. If you already have a WordPress site, take a look at either your config.php file or go to phpMyAdmin in cPanel to check your tables names. You can change it by only numbers, letters and underscore.

In case you run multiple WordPress websites, you could use a unique combination of letters and stick with it for all your installations. In this article, we will show you how to change your default WordPress table prefix. You can change the default table prefix manually as well as by using plugins. 

Methods to change the default WordPress table prefix

By using plugins:

There are many plugins available to change the default WP table prefix. But the most common one used is the WordPress change table prefix. It is a unique plugin that will allow you to change your WordPress website table prefix with a single click. Not only single WordPress but using this plugin you can change the database tables prefix of multisite installation as well.  

This plugin will be available in your WordPress plugin repository. You can directly install on WordPress dashboard > plugins > add new, and then search for the plugin name. Once you view this plugin, click on the “install now” button.

Steps to change the default table prefix in WordPress Manually

Step 1: Backup your database:

Create the latest backup copy of your WordPress database from your phpMyAdmin web interface using the export function. And then click on the ‘export’ tab at the top. Later follow the steps as displayed on the screen. Or in the cPanel click on the ‘backups’ icon and click on ‘generate/download a full backup’  and proceed with a ‘home directory backup’.

Step 2: Change Table Prefix

Now open the wp-config.php file and change your table prefix from wp_ to whatever prefix you wish to give. Here we have given wp_Sd4o7ups43_ for this article. Save and upload it to your server using FTP(I use FileZilla) client software.

Step 3: Change all your WordPress table names:

Go to your cPanel and click phpMyAdmin and from your WordPress database, select the SQL tab.

phpmyadmin SQL

And enter the commands to rename all your 11 tables at once and then click “Go”. You might have more tables starting with “wp_prefix”, that need editing, make sure to rename all tables.

[php]RENAME table `wp_commentmeta` TO `wp_Sd4o7ups43_commentmeta`;
RENAME table `wp_comments` TO `wp_Sd4o7ups43_comments`;
RENAME table `wp_links` TO `wp_Sd4o7ups43_links`;
RENAME table `wp_options` TO `wp_Sd4o7ups43_options`;
RENAME table `wp_postmeta` TO `wp_Sd4o7ups43_postmeta`;
RENAME table `wp_posts` TO `wp_Sd4o7ups43_posts`;
RENAME table `wp_terms` TO `wp_Sd4o7ups43_terms`;
RENAME table `wp_term_relationships` TO `wp_Sd4o7ups43_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_Sd4o7ups43_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_Sd4o7ups43_usermeta`;
RENAME table `wp_users` TO `wp_Sd4o7ups43_users`;[/php]

For instance, you want to replace wp_ with wp_Sd4o7ups43_ and then run the SQL commands. Keep changing the table names until all your WordPress tables have the new prefix.  If you can’t see the new table names, either refresh the page or log out from phpMyAdmin and log back in.

Step 3: Edit the wp_options tables:

Now search the wp_Sd4o7ups43_options table for any instances of the old prefix(wp_). To do this, select the wp_Sd4o7ups43_options table and click on the “Browse” tab. You will see all the records stored in that table.

Search for the option_name field and change wp_user_roles along with any other records (starting with wp_) created by plugins, custom scripts, and probably others. Rename any options that begin with wp_to the new prefix.

You can change each record by clicking on the “edit” for the record. Make sure you don’t miss any records.

You can also execute a SQL command to find the records that need editing:

[php]SELECT * FROM `wp_Sd4o7ups43_options` WHERE `option_name` LIKE ‘%wp_%'[/php]

Step 4: Edit the wp_usermeta table:

Finally, apply changes to wp_Sd4o7ups43_usermeta table formally (wp_usermeta). Search for all instances of the old wp_prefix. Select the  wp_Sd4o7ups43_usermeta table and then click on the “Browse” tab. Search for the meta_key field records that start with the old wp_prefix.

Edit each record by clicking on the “edit”. Make sure you don’t miss any records. You don’t edit any records starting with prefix_wp_, edit only the records starting with prefix wp_. You can also execute a SQL command to find the records that need editing:

[php]SELECT * FROM `wp_Sd4o7ups43_usermeta` WHERE `meta_key` LIKE ‘%wp_%'[/php]

Step 5: Change Table Prefix

Now open the wp-config.php file and change your table prefix from wp_ to whatever prefix you wish to give. Here we have given wp_Sd4o7ups43_ for this article. Save and upload it to your server.

Step 6: Test your WordPress website:

The important step is to test your WordPress website for proper functionality. Test your plugins, contact form, search fields, posts, pages, comments, administration area, and anything else available on your website. If your website is working as before, then the table prefix change is working successfully.

Conclusion

Overall, changing the default WordPress prefix “wp_” to something different is to increase the security of your WordPress website. Hope you liked our article about the steps to change your default WordPress table prefix.

If you have any queries please don’t hesitate to comment us. You can subscribe to us on Facebook and Twitter.

7 thoughts on “Steps to Change WordPress Table Prefix to Improve Security”

  1. WordPress is a highly customizable CMS that have been adopted by millions around the web.
    Unfortunately, with the so much popularity, WordPress became a top target of many hackers who created automated scripts to target various vulnerabilities in the WordPress. One of the ways to harden the security of your WordPress website is to change default database prefix from “wp_” to something else.

    Reply
  2. Thanks for shedding light on this subject (no pun intended). I don’t think, though, that it is fair to discredit the practice of changing DB prefixes completely. You are right to advise against these plugins which do the job for you. But if done by hand, with a quick SQL query and change in the wp-config file, you have easily done the job with zero risks involved.
    You are right to assume that most burglars will bring a flashlight to do the job. But it is also safe to assume that there are some out there that won’t. If changing table prefixes properly/directly helps to defend against that small percentage of attacks who don’t run the prefix query — even if it is just, say, 1% of all SQL injections — it is worth it in my eyes.

    Reply
  3. Hey! I changed DB table prefix but my site’s login URL not working. It shows me “This has been disabled”.
    Please do me the needful. awaiting for your reply

    Reply
  4. I have a query. assume that I have changed all my prefix from wp_something to some other name. these changes will be done to the existing fields in the database only. but won’t the codes in my WordPress .php files remain the same??? so next time for any new user registration or some other registration, the entities will again be saved as wp_something as the main code in the .php files remains unchanged… ???
    thanks….

    Reply
  5. Well, everything is just fine… But when I’m going back to my site, it makes me the 5 minutes install again…
    I think I missed something? can you suggest me what to do?

    Reply
  6. Its as if you read my mind! You may actually know a lot concerning this like
    you wrote the publication in it or something. I think that you could do with
    some pics to drive the note home a bit, but other than that,
    this is a fantastic blog. An excellent read. I’ll definitely be back.

    Reply

Leave a Comment