There are different procedures that you can use to rename the WordPress database prefix. It depends on whether you have already installed WordPress or not. If you have not installed WordPress yet, you can simply specify a different database table prefix from the WordPress installation wizard or pre-define it in the wp-config.php file before running the installation. If you already installed WordPress, follow the below step by step procedure.

Change WordPress Database Table Prefixes

Before you start

We recommend you to backup your WordPress database before you perform anything suggested in this tutorial. We also recommend you to redirect your visitors to a temporary maintenance page. If you are not comfortable with using phpmyadmin and MySQL, hire professionals to do the job for you.

Change Table Prefix in wp-config.php file

Open your wp-config.php file, which can be found in the WordPress root directory, and change the $table_prefix variable value from wp_ to something else, like ra66be81_.

WP White Security Tip: Use only letters, numbers and underscores for the table prefix and try not to use dictionary words. Be creative, you do not need to remember such value.

After the change, the line in wp-config.php should look like:

$table_prefix=’ra66be81_’;

Change all WordPress Database Tables Name

To change the database tables name you need access to your WordPress MySQL database. You can access the WordPress database through phpMyAdmin which is accessible from your hosting provider’s CPanel. Below is a screenshot of the WordPress database tables in phpMyAdmin.

The WordPress MySQL database contains 11 tables by default and as you can notice from the above screenshot, they all start with the wp_ prefix. You might have more tables if you installed a plugin that adds an own table to the database. You can rename the tables manually, one by one. Alternatively use the below script to automate the renaming of the tables. To use the below SQL query, click on the SQL tab (highlighted in the above screenshot), copy the content, paste it and change the prefix to the prefix you’ve chosen.

RENAME table `wp_commentmeta` TO `ra66be81_commentmeta`; RENAME table `wp_comments` TO `ra66be81_comments`; RENAME table `wp_links` TO `ra66be81_links`; RENAME table `wp_options` TO `ra66be81_options`; RENAME table `wp_postmeta` TO `ra66be81_postmeta`; RENAME table `wp_posts` TO `ra66be81_posts`; RENAME table `wp_terms` TO `ra66be81_terms`; RENAME table `wp_term_relationships` TO `ra66be81_term_relationships`; RENAME table `wp_term_taxonomy` TO `ra66be81_term_taxonomy`; RENAME table `wp_usermeta` TO `ra66be81_usermeta`; RENAME table `wp_users` TO `ra66be81_users`;

If you have other tables in your WordPress database using the same prefix, such as tables created by plugins, you can add them to this query as well. For your reference the syntax of the above SQL query is the following:

RENAME table `[old_table_name]` TO `[new_table_name]`;

The Options table

WordPress stores all the global options in the Options table. In this table there are some entries which also need to have their prefix changed. To retrieve a list of all the entries that are using the wp_ prefix and needs changing, use the following SQL query:

SELECT * FROM `ra66be81_options` WHERE `option_name` LIKE '%wp_%'

The query might return a good number of entries that need to be changed. It is important to change them all to avoid having problems.

The UserMeta table

The WordPress UserMeta table contains all the information about registered users, such as personalised settings. In this table there are also a number of entries that need to have their prefix changed. To retrieve a list of all entries that are using the wp_ prefix, use the following SQL query:

SELECT * FROM `ra66be81_usermeta` WHERE `meta_key` LIKE '%wp_%'

The number of entries returned when running this query might vary. It depends of how many WordPress plugins you have installed etc.

Backup and Test the Change

That should be it. Before you do any further changes, make a backup of WordPress again and proceed with testing the changes. Visit at least one page, one blog post and try to login to the WordPress dashboard (wp-admin section) to confirm that everything is working fine.