How to change the prefix on a WordPress database to improve security
The database is like a brain for your WordPress site. All the information of your site is stored in it. This makes the database the preferred target of hackers and spammers who use automatic codes for SQL injections.
Unfortunately, many people forget to change the database prefix during WordPress installation, it makes it easier for hackers to plan a mass computer attack by targeting the default prefix wp_
For security reasons it is advisable to modify the default wp_ prefix of your wordpress site.
In this tutorial I show you how to modify the prefix of the WordPress database to improve the security of your site.
1-Change the default wp_ prefix in the wp-config.php file
From your FTP server open the wp-config.php file located in the root of your site and modify the prefix table line wp_ with another prefix that contains numbers, letters and underscores like this: wp_m1234567890
the default wp_ prefix for your wordpress site.
$table_prefix = 'wp_';
I replace the default wp_ prefix with $table_prefix = 'wora250582_';
2-Modify all the tables in the database
To modify the database tables access your database via phpMyadmin then modify the table names by the one you specified in the wp-config.php file as below
Database |
phpMyAdmin |
database tables |
The SQL query code:
RENAME table `wp_commentmeta` TO `wp_m1234567890_commentmeta`;RENAME table `wp_comments` TO `wp_m1234567890_comments`;RENAME table `wp_links` TO `wp_m1234567890_links`;RENAME table `wp_options` TO `wp_m1234567890_options`;RENAME table `wp_postmeta` TO `wp_m1234567890_postmeta`;RENAME table `wp_posts` TO `wp_m1234567890_posts`;RENAME table `wp_terms` TO `wp_m1234567890_terms`;RENAME table `wp_termmeta` TO `wp_m1234567890_termmeta`;RENAME table `wp_term_relationships` TO `wp_m1234567890_term_relationships`;RENAME table `wp_term_taxonomy` TO `wp_m1234567890_term_taxonomy`;RENAME table `wp_usermeta` TO `wp_m1234567890_usermeta`;RENAME table `wp_users` TO `wp_m1234567890_users`;
SQL request:
To change the database tables launch an SQL query, use the SQL query code above
Modification of the wp_options table
You should search the options table for all other fields that use wp_ as a prefix, so that you can replace them. To facilitate the process, use this query:
SELECT * FROM `wp_m1234567890_options` WHERE `option_name` LIKE
'%wp_%'
Modification of the wp_usermeta table
Next, you need to find the user meta for all the fields that use wp_ as a prefix, so you can replace it.
Use this SQL query
SELECT * FROM `wp_m1234567890_usermeta` WHERE `meta_key` LIKE
'%wp_%'
The number of entries can vary depending on the number of plugins you use. Change everything that has wp_ to the new prefix.
Conclusion:
Now test your WordPress site. If you followed the above steps, everything should work fine.
If you have enabled multisite, WordPress uses a few additional tables that you will have to modify in the same way
Important:
Back up your WordPress database before doing anything suggested in this tutorial.
It is important to back up your site database daily
Redirect your visitors to a temporary maintenance page.