How to Change WordPress Database Prefix (3 Easy Steps)

How to Change WordPress Database Prefix (3 Easy Steps)

Want to change WordPress database prefix?

WordPress websites are made of files, folders, and a database. The database is an important part of your site because it stores posts, pages, comments, user data, settings, and plugin configurations, among other resources.

Given the importance of the database, hackers often target it (especially during SQL injection attacks) in hopes of manipulating or extracting sensitive data from the website. This is why it is crucial to implement strong security measures. And it just so happens that one of the great ways to protect it is by changing your WordPress database prefix.

Since all WordPress websites have the same prefix (i.e., “wp_”), it’s easier for hackers to use it to access your site. Modifying the database prefix to something unique will throw hackers off their tracks.

Let’s learn 👨‍🎓 how to change WordPress database prefix and strengthen your site’s security.

Things to do before changing WordPress database prefix

Before you start to change WordPress database prefix, you should first understand what it is. Then you need to carry out the following measures:

⚠️ These are not optional measures. You need to ensure that these are implemented before moving on to the next section.

1. Take a backup: 💽 To change your database prefix, you will need to go to the backend of your website and make modifications there. This is risky because if something goes wrong, you could end up with a broken website. To protect it from such catastrophes, take a backup.

2. Deactivate plugins and themes: 🎨 Changing the database prefix can break the functions powered by plugins and themes installed on your website. You need to deactivate all your plugins and switch to a default WordPress theme. Reactivate them only after modifying the database prefix.

3. Change WordPress database prefix in the wp-config.php file: 👨‍💻 The wp-config file contains database credentials, and it needs to be modified before you change the database prefix. Incorrect credentials tend to trigger the “database connection issue” error, which makes a website blank.

You can access the config file by using an FTP client or through your hosting account.

Use any of the two methods to open the File Manager and go to public_html → wp-config.php.

Right-click on the config file and select Edit.

Locate the database prefix inside the file and replace it with a new one.

Save your changes and exit the page.

Changing database prefix in wpconfig.

After implementing these measures, proceed with changing the WordPress database prefix.

Best methods how to change WordPress database prefix

The database prefix can be changed using a plugin or via phpMyAdmin.

Let’s dive into both of these methods.

Method 1: Use a plugin to change the database prefix 🔌

The easiest way to change the WordPress database prefix is to use a plugin.

Dedicated plugins, like Brozzme DB Prefix & Tools Addons, WP Prefix Changer, Rename DB Table Prefix, etc., can help you change the database prefix. But most of these plugins are not updated, which could mean that they have been abandoned by the developers.

An example of an outdated plugin in the WordPress repository.

These days, most security plugins (like All-In-One Security, iThemes Security, etc.) offer database modification facilities, so perhaps these dedicated plugins were finding it difficult to attract users.

We don’t recommend using outdated plugins because they are the number one cause of websites getting hacked.

However, you can use a security plugin to change database prefixes if you have one installed. If not, then we recommend proceeding with the next method.

Method 2: Use the phpMyAdmin to change the database prefix ⚙️

PhpMyAdmin is a tool used for managing or interacting with your site’s database. It has a user-friendly interface and can be used to change database prefixes by non-techie website owners.

To change the database prefix, you need to carry out the following steps:

  • Rename database tables in phpMyAdmin
  • Update prefix in the Options table
  • Update prefix in Usermeta table

👉 Let’s take a look at how to carry out these steps:

Rename database tables in phpMyAdmin 🖱️

The phpMyAdmin can be accessed via your hosting account.

On Namecheap, where our demo site is hosted, we were able to access phpMyAdmin using the cPanel.

phpMyAdmin in cPanel.

Locate the phpMyAdmin on your hosting account and open it.

Next, select the database from the left panel. As soon as you do that, several tables will appear on the right side of the screen. These tables contain crucial information about your WordPress website.

WordPress database in phpMyAdmin.

💡 Quick side note: Some phpMyAdmins contain multiple databases because the tool can host databases for various websites. In such cases, it’s important to make sure that you are identifying and selecting the correct database.

Multiple databases in phpMyAdmin.

To identify the correct database, select a database, go to the wp_options table, and check the siteurl option. It contains the URL of the website to which the database belongs.

Keep checking all the databases in this manner until you find the correct database.

After locating the correct database, select the database and then scroll down to the end of the page and hit the Check All option.

Next, click on With selected, and from the dropdown menu select the Replace table prefix option.

And replace the old prefix with the new prefix. Make sure it’s the same prefix you added earlier in your wp-config.php file.

Replace database table in phpMyAdmin to help change WordPress database prefix.

Update the prefix in the Options table 🖱️

In the previous section, we showed you how to rename prefixes. In this section, we are going to ensure that all the table prefixes are renamed by running an SQL query. Here’s what you need to do:

From the top of the screen, select the SQL option and insert the following line in the blank section of the SQL page:

SELECT * FROM `xxx_options` WHERE `option_name` LIKE '%wp_%'

Make sure you replace the “xxx” with your new prefix and then hit enter.

Running an SQL query in phpMyAdmin to change WordPress database prefix.

The search will retrieve several tables. You need to manually edit them one by one to rename the prefixes.

Update prefix in Usermeta table 🖱️

You need to run another SQL query to ensure that all your tables are renamed. Here’s the query:

SELECT * FROM `xxx_usermeta` WHERE `meta_key` LIKE '%wp_%'

Be sure to replace the “xxx” with your new prefix before hitting enter.

After running the query, some tables will appear. You need to edit those tables and rename their prefixes.

That’s it. You have changed your WordPress database and secured your website.

Things to do after changing WordPress database prefix

In the pre-database prefix change measures, you deactivated the plugins and the theme installed on your website.

After changing the database prefix, you need to open your WordPress dashboard and reactive your plugins and theme.

That’s it. With that, we have come to the end of this tutorial on how to change WordPress database prefix.

Conclusion 🧐

Changing the database prefix is a great way to ensure that your website is safe from SQL injection attacks.

To modify the WordPress database prefix, you can use a security plugin offering database prefix rename facilities or access phpMyAdmin via your hosting account and modify the prefix there.

🖱️ Using the plugin is easy, but if you don’t want to take that route, then use phpMyAdmin to carry the following steps:

  1. Rename database tables in phpMyAdmin
  2. Update prefix in the Options table
  3. Update prefix in the Usermeta table

Be sure to take a backup of your website and deactivate all your themes and plugins before modifying the database prefixes. Also, remember to reactive them after changing the prefixes.

👉 After changing the database prefix, we recommend reading through the following guides and implementing the measures listed in the article to further strengthen the security of your database:

If you have any questions about how to change WordPress database prefix, leave us a comment below.

Free guide

4 Essential Steps to Speed Up
Your WordPress Website

Follow the simple steps in our 4-part mini series
and reduce your loading times by 50-80%. 🚀