How To Change The WordPress Database Prefix To Improve Security

WordPress is a content management system that stores your website’s content, posts, pages, themes, and plugins in a database. A database is the storage of the website and contains every single information. While installing WordPress, people tend to leave the prefix wp_, which is the default. This makes it the target for hackers and spammers and can run automated codes for SQL injections. The safest way to protect your database is by changing the database prefix while setting up your WordPress site. In this tutorial, you will learn how you can make your database safe by changing the default database prefix. It is always recommended to make a full backup of your website before making changes to your database.

Step 1:

Login to your cPanel and locate File Manager. Click File Manager to open the WordPress directory. How To Change The WordPress Database Prefix To Improve Security

Click public_html and locate wp-config.php. Right click wp-config.php and Click Edit.

How To Change The WordPress Database Prefix To Improve Security

Step 2:

A pop window appears after you click Edit. Again Click Edit on the window to open the editor. Search for the following line of code and modify it with the choice of your prefix.

$table_prefix  = 'test_';

Here, the default wp_ has been changed to test_
Only numbers, letters and underscores can be used as a prefix name.

Step 3:

After changing the wp-config.php, you also need to change it in your database. You can access it through phpMyAdmin from your cPanel. From your cPanel, Click phpMyAdmin to open the phpMyAdmin control panel. Look at the image below:

How To Change The WordPress Database Prefix To Improve Security

Step 4:

In the phpMyAdmin control panel, Click SQL tab to open the SQL query window. There are 12 WordPress tables, changing the prefix manually would be time consuming. Here, you will execute a query which will automatically change all the default prefix name to the name of your choice.

RENAME table`wp_commentmeta`TO`test_commentmeta`;
RENAME table`wp_comments`TO`test_comments`;
RENAME table`wp_links`TO`test_links`;
RENAME table`wp_options`TO`test_options`;
RENAME table`wp_postmeta`TO`test_postmeta`;
RENAME table`wp_posts`TO`test_posts`;
RENAME table`wp_terms`TO`test_terms`;
RENAME table`wp_termmeta`TO`test_termmeta`;
RENAME table`wp_term_relationships`TO`test_term_relationships`;
RENAME table`wp_term_taxonomy`TO`test_term_taxonomy`;
RENAME table`wp_usermeta`TO`test_usermeta`;
RENAME table`wp_users`TO`test_users`;

Execute the above query in the SQL query window to change the prefix of the database at once.

You might want add lines for plugins that have their own tables in the database.

How To Change The WordPress Database Prefix To Improve Security

Step 5:

If there are other tables created by third-party plugins, you need to change the prefix name accordingly by running the query. After changing all instances of the wp_ prefix, you need to check the working of your site. Test the pages, posts, admin dashboard, etc to make sure everything is working fine as before.

Conclusion:

Congratulations, You have successfully secured your database from hackers and spammer who are waiting to attack using the default database prefix. Always remember to keep the latest backup. It is always easy to restore to a backup if something goes wrong.

Check out these top 3 WordPress hosting services:

Was this article helpful?