Change wordpress database prefix.

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, WordFence, 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.

Yay! 🎉 You made it to the end of the article!

6 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ka Khaliq
January 3, 2024 8:52 pm

Hi there,
I’m referring to this article to update my WordPress website database prefix.
I have a confusion about updating the Options and Usermeta tables. Upon running the respective SQL queries, the results obtained, also contains some rows something like transient_wp_cloudflare OR dismissed_wp_pointers OR tlwp_feedback_data OR wpseo_social etc.
So do I need to update such rows too where wp_ is present in the middle/end OR do I just need to update rows that has the wp_ prefix at the start like wp_page_for_privacy_policy etc.
I understand that by prefix means, something at the start but still want to solve this confusion.

Member
Ivica
January 4, 2024 7:53 am
Reply to  Ka Khaliq

You only need to update the tables that have the wp_ prefix at the start. The rows with prefixes like transient_wp_cloudflare, dismissed_wp_pointers, or wpseo_social do not need to be updated as they are not part of the WordPress core tables. although there is a good practice to update these rows as well, just to be safe, it’s up to you.

To update the Options and Usermeta tables, you should focus on the rows that have the wp_ prefix at the start, such as wp_options or wp_usermeta. You can run the SQL queries specifically for these tables to update the prefixes.

If you’re unsure about performing these database operations manually, I can recommend using a reliable plugin like “Better Search Replace” to safely update the database prefixes: https://themeisle.com/blog/best-wordpress-database-plugin/.

Always remember to backup your database (and website) before making any changes to ensure that you can revert back in case of any issues: https://themeisle.com/blog/wordpress-backup-plugins-compared/ (my preffered plugin is All in one WP migration).

Ka Khaliq
January 7, 2024 2:26 pm
Reply to  Ivica

Hi,
I have successfully updated the database prefix manually using this guide. After updating, could successfully login to cpanel, admin and other authors account. The site seems to be working as expected. No obvious issues observed on the website. So far so good.
After updating, I rechecked the Options table just to verify that all tables are updated (20 entries). While I was going through, I could see a couple of duplicated entries (now a total of 22 entries) that show the previous prefix (wp_force_deactivated_plugins and wp_cloudflare_page_cache_install). These two entries are also available with the new updated prefix.
When I tried to update one of these entries with the wp_ prefix. I got an error message stating Duplicate entry.
Should I just ignore this? or what could be the solution for this?
The Usermeta table is updated correctly.

Member
Ivica
January 8, 2024 8:19 am
Reply to  Ka Khaliq

It is strongly advised not to update duplicate entries in the Options table in order to prevent potential database corruption and other complications.
In your case, it seems that the update process was unable to fully eliminate the old prefix from the table, causing the duplicated entries.

As you wrote – the website seems to be working fine, so you can ignore the duplicated entries for now, but keep a close eye on the website for any issues.

Consider manually removing duplicate entries from the Options table only as a last resort, as it can be risky and may require technical expertise.
To manually remove the duplicate entries, you can use a database management tool like phpMyAdmin or a similar tool.

There are also plugins available that can help with database maintenance and management. One such plugin is “WP-Optimize,” which allows you to clean up your WordPress database and optimize it for better performance: https://themeisle.com/blog/wordpress-database-optimization-tips/#db-plugin

Last edited 9 months ago by Ivica
Ka Khaliq
January 9, 2024 7:56 pm
Reply to  Ivica

Hi Ivica,
Thank you for your quick response.
Yes, I have been using the WP-Optimize plugin to clean the database for a while. After updating the database prefix, I used the plugin, but the duplicated entries are still there.
As you already mentioned to keep a close eye on the website. So, yesterday I noticed the cache issue on my website. Though after updating the database prefix, I cleared the Cloudflare cache too. Some changes that I made especially in the sidebars and in the Customizer tool are not visible at once, when viewing my website on different browser/devices. However, the changes made are visible when I’m logged into my admin account.
So, it seems the issue is related to the duplicated “wp_cloudflare_page_cache_install” entry. The cache was working correctly before updating the database prefix.
Since I’m not an expert of MySQL for making changes in the database. As you already mentioned, deleting duplicate entries could be risky.
So should I restore back using the backup?
I made a backup using UpdraftPlus before updating the prefix.
Or is there any other solution?

Member
Ivica
January 10, 2024 9:58 am
Reply to  Ka Khaliq

I am not sure about Cloudflare as I don’t use it – it caused me certain caching troubles on some of our clients’ sites in the past, so I don’t use it since then.

However, whenever we have some issues on sites after some updates, and before changes all worked fine, I would restore the last working backup before that, just to see how it goes, but do make backup of your current site state, just in case you should get back to it for whatever possible reasons(s).

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!