Skip to main content

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.

WordPress Database Table Prefix
[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 table wp_commentmeta TO hk_commentmeta;
RENAME table wp_comments TO hk_comments;
RENAME table wp_links TO hk_links;
RENAME table wp_options TO hk_options;
RENAME table wp_postmeta TO hk_postmeta;
RENAME table wp_posts TO hk_posts;
RENAME table wp_terms TO hk_terms;
RENAME table wp_termmeta TO hk_termmeta;
RENAME table wp_term_relationships TO hk_term_relationships;
RENAME table wp_term_taxonomy TO hk_term_taxonomy;
RENAME table wp_usermeta TO hk_usermeta;
RENAME table wp_users TO hk_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 * FROM wp_a123456_options WHERE option_name LIKE '%wp_%'

UserMeta Table

SELECT * FROM wp_123 WHERE meta_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.


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.

Leave a Reply