How To Change The WordPress Database Prefix To Improve Security

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:

A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7

How To Change the Database Port for WordPress

This guide will help you on how to change the database port of your Wordpress we
1 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Find Out the Database Details of Your WordPress Website Using cPanel

This how-to guide explains different ways to find out the database name and pass
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How To Examine And Repair A Database in PhpMyAdmin

Over the period of time, database can be corrupted and needs to repaired. This t
1 min read
Elizabeth Grom
Elizabeth Grom
Hosting Expert

How To Clean Meta Data In A WordPress Database

Overtime, we should clear up metadata in our database. This tutorial will guide
1 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top