WordPress Security

Change WordPress table prefix

It is very important that we take into account the number of WordPress that are currently active on the Internet and each and every one of them does not have to be correctly configured. Unfortunately, most of them have done a quick installation and without thinking too much about things like the administrator username and password, in the same way, very few people change the prefix of the WordPress database and that is what we are going to do today. see here.

Why change the WordPress table prefix?

All default installations have the same prefix and WordPress databases all share the table name, eg wp_users.

If we were a hacker and wanted to do a massive attack on many WordPress installations, we would set up our attack to target these tables directly. For this reason, changing the WordPress table prefix is ​​highly recommended.

Change the prefix at install time

When we are installing our WordPress with our default installer and not the one that our hosting brings us, we can insert a value for that prefix that can be totally random, since when we want to refer to this prefix we will use the variable that WordPress provides us for it .

Change database table prefix

In the screenshot above we can see the field that we have to fill in exactly. We can place a random word or a keystroke since in principle it is not necessary for us to remember this prefix.

I already installed my WordPress a long time ago, how do I change it now?

Change the prefix from wp-config.php

If we already did the installation some time ago and we need to change the WordPress table prefix, we will simply open our wp-config.php file and modify the following line.

$table_prefix  = 'wp_';

We change it for what we want and that's it.

I recommend that you make a backup copy of the files and the database before touching anything.

After this you will have to access your PHPMyAdmin where your database is hosted and modify the information of the database through SQL queries so that it corresponds to what is indicated in the wp-config.php

1 First the general query to quickly modify all tables

RENAME table `wp_commentmeta` TO `[TUPREFIJO]_commentmeta`;
RENAME table `wp_comments` TO `[TUPREFIJO]_comments`;
RENAME table `wp_links` TO `[TUPREFIJO]_links`;
RENAME table `wp_options` TO `[TUPREFIJO]_options`;
RENAME table `wp_postmeta` TO `[TUPREFIJO]_postmeta`;
RENAME table `wp_posts` TO `[TUPREFIJO]_posts`;
RENAME table `wp_terms` TO `[TUPREFIJO]_terms`;
RENAME table `wp_termmeta` TO `[TUPREFIJO]_termmeta`;
RENAME table `wp_term_relationships` TO `[TUPREFIJO]_term_relationships`;
RENAME table `wp_term_taxonomy` TO `[TUPREFIJO]_term_taxonomy`;
RENAME table `wp_usermeta` TO `[TUPREFIJO]_usermeta`;
RENAME table `wp_users` TO `[TUPREFIJO]_users`;

If the code generates an error, take a look at the format of the quotes since it may be that when copying from the browser they are done in an incorrect format.

2 seconds perform a specific query on the wp_options table.

SELECT * FROM `[TUPREFIJO]_options` WHERE `option_name` LIKE 'wp_%'

This directive will return a series of results that you must modify by hand, removing the old prefix and writing the new one.

3. Third, perform a specific query for the usermeta table

SELECT * FROM `[TUPREFIJO]_usermeta` WHERE `meta_key` LIKE 'wp_%'

We perform exactly the same step as in the previous point.

If you don't dare to directly modify the code or simply prefer not to, the next option would be to have a plugin for it.

Change the prefix from ITheme Security

Whenever I talk about security I recommend this plugin and for this case it is very useful for us since simply in one of its functionalities within the setting we can find exactly what we need.

After clicking on settings, we would go to the advanced tab. Around 5 boxes with different functionalities will be loaded, one of them is “Change database prefix”.

Click on configure settings and change the selector that is set to no by default, to set it to si. Then we click on save settings and voila we would have our prefix changed.

And these would be the different ways to change the prefix of the WordPress tables, greetings and see you next week 😀

¡Subscribe to our newsletter and receive our offers, news and discounts directly to your email!