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_%';
References:
https://digwp.com/2010/10/change-database-prefix/
https://digwp.com/2010/10/change-database-prefix/#comment-10834
https://www.wordfence.com/blog/2016/12/wordpress-table-prefix/
Hi Sridhar, this seems to be causing 2 errors:
Step 3 error: #1054 – Unknown column ‘wp_%’ in ‘where clause’
Step 4 error: #1054 – Unknown column ‘wp_%’ in ‘where clause’
After only completing steps 1 and 2 I can no longer log in to the admin area.
Sorry about that David.
I am not sure how to fix that.
I have just updated the tutorial to add a step asking readers to take full backup of the site and database as Step 0.
Have you taken a backup by any chance?