How to change database tables’ prefix in WordPress

Below are the concise steps to change WordPress database tables’ prefix to prefix_ after WordPress has been installed with the tables having the default wp_ prefix.

In the instructions below, replace prefix_ with whatever is your desired prefix (do not use upper case).

Step 0

Take a full backup of your site and the database.

Step 1

Edit wp-config.php in the site’s root and change

$table_prefix = 'wp_';

to

$table_prefix = 'prefix_';

Step 2

Open your database management tool like phpMyAdmin or Adminer.

Run this SQL query:

RENAME table `wp_commentmeta` TO `prefix_commentmeta`;
RENAME table `wp_comments` TO `prefix_comments`;
RENAME table `wp_links` TO `prefix_links`;
RENAME table `wp_options` TO `prefix_options`;
RENAME table `wp_postmeta` TO `prefix_postmeta`;
RENAME table `wp_posts` TO `prefix_posts`;
RENAME table `wp_termmeta` TO `prefix_termmeta`;
RENAME table `wp_terms` TO `prefix_terms`;
RENAME table `wp_term_relationships` TO `prefix_term_relationships`;
RENAME table `wp_term_taxonomy` TO `prefix_term_taxonomy`;
RENAME table `wp_usermeta` TO `prefix_usermeta`;
RENAME table `wp_users` TO `prefix_users`;

Step 3

Run this SQL query to change the prefix in options table:

UPDATE `prefix_options` SET `option_name`=REPLACE(`option_name`,'wp_','prefix_') WHERE `option_name` LIKE 'wp_%';

Step 4

Run this SQL query to change the prefix in usermeta table:

UPDATE `prefix_usermeta` SET `meta_key`=REPLACE(`meta_key`,'wp_','prefix_') WHERE `meta_key` LIKE 'wp_%';
This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.