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
Table of Contents
- 1 Methods to change the default WordPress table prefix
- 1.1 By using plugins:
- 1.2 Steps to change the default table prefix in WordPress Manually
- 2 Conclusion
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.
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.
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`;
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:
SELECT * FROM `wp_Sd4o7ups43_options` WHERE `option_name` LIKE '%wp_%'
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:
SELECT * FROM `wp_Sd4o7ups43_usermeta` WHERE `meta_key` LIKE '%wp_%'
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.
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.
Prabhu Ganesan provides his web development and WordPress services independently. He is the founder of WPBlogX. He is very much involved in WordPress as it becomes second nature for him. You can get in touch with him by visiting his website – WPBlogX.com and you can also find him on Twitter @gprabhucbe.