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%.ย ๐Ÿš€