How to Easily Change WordPress Database Table Prefix
During WordPress installation, it asks you if you want to change your database table prefix “wp_” to something. We usually skip this thing, so WordPress automatically creates a database with its default table prefix “wp_”.
Many WordPress users often ask how to change WordPress database table prefix. They believe by changing the default table prefix in WordPress will improve their site security. According to WordFence, it doesn’t do anything to enhance your site security and it is a too risky process. In some cases, users attempt to change or modify their database without taking a backup and as a result, they end up by losing their site.
Why Changing Database Table Prefix Doesn’t Enhance site Security?
Now let’s talk about the method of hacking WordPress database. Usually, the most common attack is called “SQL injection” where a hacker runs a vulnerability in an application to gain access and the easiest way to do so is through a plugin. If anyhow, an attacker gains access to your database, the attacker will have the same capability that you have in your database. They usually run a script in your database to get all the details.
By changing your database table prefix in WordPress does nothing for enhancing your site security because the attacker is gaining access through a vulnerable application, such as plugin and they can easily get all the details of your site.
We highly suggest you never download any nulled plugin or theme because, a nulled plugin or theme can contain vulnerable scripts, if you use it, hackers will easily get access to your database and can destroy your site.
If you want to secure your site and database, you can use an excellent security service like Securi. Securi is a complete website security solution, it protects your site from attackers like DDoS, brute force, vulnerability attacks etc. It also helps to clean your hacked site and much more. If you are serious about your WordPress site security, you should use Securi. Check Securi.
How to Change WordPress Database Table Prefix
As we already mentioned, you don’t need to change your database prefix for security purpose. If you want to change database prefix in your WordPress site, you can do it. We will show you the exact steps how you can easily change your database prefix in your WordPress site.
Preparation: Before we start, I highly recommend you to take a full backup of your site and database. In case something goes wrong, you can easily restore your database with one click. BackupBuddy is a good backup plugin and you can restore your database or site with just one click.
There are two ways you can change your WordPress database prefix,
- You can change your database prefix using phpMyAdmin
- You can change WordPress database table prefix using a plugin
In this article, we will show both methods. So let’s dig into it.
Method 1, Change Database Table Prefix Using phpMyAdmin
This is a very common method for changing your database prefix. For this, you need to login to your hosting cPanel.
Step 1, Edit wp-config.php File
After logging to your hosting cPanel, go to your root directory where you have installed your WordPress. Open the wp-config.php file and find the line “$table_prefix = ‘wp_’;”.
Change the table prefix line wp_ to something you like, for example, ry_ or xz_013654. You can only use letters, numbers, and underscores.
When you finished editing your table prefix, don’t forget to save it.
Step 2, Change Database Table Name In phpMyAdmin
In the next step, you need to access your database through phpMyAdmin. If you are using cPanel WordPress hosting, you can easily find phpMyAdmin under database section.
You can see different tables and it depends on your site structure or how many plugins you have installed.
The fastest way to rename table prefix is by running SQL queries. Now run the SQL command from your SQL section that I have shown in the above image. We have a SQL query that you can use:
RENAME table `wp_commentmeta` TO `jr_commentmeta`; RENAME table `wp_comments` TO `jr_comments`; RENAME table `wp_links` TO `jr_links`; RENAME table `wp_options` TO `jr_options`; RENAME table `wp_postmeta` TO `jr_postmeta`; RENAME table `wp_posts` TO `jr_posts`; RENAME table `wp_termmeta` TO `jr_termmeta`; RENAME table `wp_terms` TO `jr_terms`; RENAME table `wp_term_relationships` TO `jr_term_relationships`; RENAME table `wp_term_taxonomy` TO `jr_term_taxonomy`; RENAME table `wp_usermeta` TO `jr_usermeta`; RENAME table `wp_users` TO `jr_users`;
This is the default SQL command and if you have extra tables, you can easily add them. Don’t panic. It’s so easy. Like I want to change wp_ to jr_, so if you want to change an extra table name, you need write this way:
RENAME table `wp_yoast_seo_links` TO `jr_yoast_seo_links`;
After entering SQL commands, click on GO to run the process.
Step 3, Rename the wp_fields in Database Tables
There are still two fields that are using wp_ as a prefix (wp_options and wp_usermeta), by running the following queries, we can easily change the prefix of those fields. It may vary how many plugins you have installed, if you find more wp_ fields, you need to rename them too.
UPDATE `jr_options` SET `option_name`=REPLACE(`option_name`,'wp_','jr_') WHERE `option_name` LIKE '%wp_%'; UPDATE `jr_usermeta` SET `meta_key`=REPLACE(`meta_key`,'wp_','jr_') WHERE `meta_key` LIKE '%wp_%';
After entering the SQL scripts, hit the Go button to continue. You have now successfully changed your database table prefix in WordPress.
Here’is how it looks after changing the database prefix.
Method 2, Change Database Table Prefix Using a Plugin
If you don’t want to touch your database or any manual process, then you can do it by using Brozzme DB plugin. Using this plugin, you can modify your database prefix from everywhere (database and wp-config.php) with just one click.
First, install and activate Brozzme DB plugin. From your WordPress admin panel, go to Tools> DB PREFIX. By default, this plugin automatically generates a new prefix, if you don’t like, you can enter your own prefix. You can only use letters, numbers, and underscores.
At last click on Change DB Prefix and you are done.
Test Your WordPress Site
Once you changed WordPress database prefix, it’s time to test your site. First, you need to login to your site, and test pages, posts, search, and everything else you can think of. If your website is working well as before, take another backup of your database.
I hope this tutorial helped you to understand how attacks attack a database using a vulnerable application and how to avoid them, we also showed how to change Database Table Prefix in WordPress using a plugin and using phpMyAdmin. If you are getting any error, please do let us know in the comment section. Don’t forget to share this article with your friends.
Other Helpful Articles,