WordPress is an open-source web publishing tool that helps you to create the website and blog of your choice. When it comes to security it offers the best, but due to the number of users and popularity, it has become the prime target for hackers and attackers to breach. It will be even easier to nuke the site if you are using the default prefix wp_ on your database. So it is important to change your WordPress Database Table Prefix to something that makes it difficult for the intruder to crack. Hope you change your Database table prefix, if not then change now by following the steps below.
Methods to Change WordPress Database Table Prefix
- Via wp-config.php
- Using SQL Query
- Rename Options and UserMeta table
- Using Plugins
How to Change Database Table Prefix Via wp-config.php
This method is used to change only the prefix of your WordPress database table and it will be applied to all tables.
[1] Launch your WordPress FTP and login to it. [2] Navigate to wp-config.php from the WordPress root directory. [3] Open the wp-config.php file in the code editor. [4] Locate the following line of code: $table_prefix = ‘wp_123’; [5] Change the Prefix wp to hk or you prefix you wish for.Note: You can add only numbers, text, and underscores as a prefix.
[6] Once change save the changes.How to Change Database Table Prefix using SQL Query
This method involves some SQL code which is pretty simple to understand and implement using which you can change all table names and its prefix individually.
[1] Go to cPanel of your WordPress hosting site. [2] Under the Database section, choose phpMyAdmin. [3] Now you can see the list of tables available on your WordPress site. [4] Click on SQL above the list of tables. [5] Enter the following line of code to replace and rename the table.RENAME tablewp_commentmeta
TOhk_commentmeta
; RENAME tablewp_comments
TOhk_comments
; RENAME tablewp_links
TOhk_links
; RENAME tablewp_options
TOhk_options
; RENAME tablewp_postmeta
TOhk_postmeta
; RENAME tablewp_posts
TOhk_posts
; RENAME tablewp_terms
TOhk_terms
; RENAME tablewp_termmeta
TOhk_termmeta
; RENAME tablewp_term_relationships
TOhk_term_relationships
; RENAME tablewp_term_taxonomy
TOhk_term_taxonomy
; RENAME tablewp_usermeta
TOhk_usermeta
; RENAME tablewp_users
TOhk_users
;
The above mentioned is the code for 11 default WordPress tables for the additional table that added from the plugin can be replaced by adding it.
RENAME table (table name) TO (the name you wish to change);[6] Once the name is changed, save the changes.
Rename Options and UserMeta table
Apart from the database table, two other fields that use wp as the prefix and to replace that follow the steps below.
Options Table
SELECT * FROMwp_a123456_options
WHEREoption_name
LIKE '%wp_%'
UserMeta Table
SELECT * FROMwp_123
WHEREmeta_key
LIKE '%wp_%'
How to Change Database Table Prefix Using Plugin
If you are not interested in manual coding or jumping into SQL and database kinds of stuff, then you can use the Change Table Prefix plugin and rename the database table prefix in no matter of time.
Conclusion
These are some of the possible ways to change the Database Table prefix and safeguard your site from intruders. Before making any changes in the database, make sure to backup your complete WordPress database file. Also, if the site is active, it is better to redirect all your site traffic to a temporary maintenance page until the changes being done. Hope this helps you change your database prefix and if you are facing any trouble let us know in the comments section below. For more WordPress tips and tricks, explore our blog.