Follow these few steps to rename the table prefix of your existing WordPress site.

Edit wp-config.php and change

$table_prefix = 'wp_';

to any other prefix, try to make it abstract and hard to be guessed by anyone, for example:

$table_prefix = 'v5r33w67ee_';

Rename the tables in your database, these are the SQL queries to rename the core tables:

RENAME table `wp_users` TO `v5r33w67ee_users`;
RENAME table `wp_usermeta` TO `v5r33w67ee_usermeta`;
RENAME table `wp_comments` TO `v5r33w67ee_comments`;
RENAME table `wp_commentmeta` TO `v5r33w67ee_commentmeta`;
RENAME table `wp_links` TO `v5r33w67ee_links`;
RENAME table `wp_options` TO `v5r33w67ee_options`;
RENAME table `wp_posts` TO `v5r33w67ee_posts`;
RENAME table `wp_postmeta` TO `v5r33w67ee_postmeta`;
RENAME table `wp_terms` TO `v5r33w67ee_terms`;
RENAME table `wp_term_taxonomy` TO `v5r33w67ee_term_taxonomy`;
RENAME table `wp_term_relationships` TO `v5r33w67ee_term_relationships`;

Add the queries to rename any other existing table that have been created from other plugins or themes.
You can also rename the tables in phpMyAdmin, by clicking on the operations tab

Update the references to the old table prefix in the usermeta and options table running these SQL queries.

UPDATE `v5r33w67ee_usermeta` SET `meta_key` = REPLACE( `meta_key`, 'wp_', 'v5r33w67ee_' );
UPDATE `v5r33w67ee_options` SET `option_name` = 'v5r33w67ee_user_roles' WHERE `option_name` = 'wp_user_roles';
Rename table prefix on existing WordPress site
Tagged on:     

3 thoughts on “Rename table prefix on existing WordPress site

  • October 23, 2014 at 18:13
    Permalink

    Nice.
    Would the WP core automatic update break the site after renaming the DB prefix?

    Thank you.

    Reply
    • October 30, 2014 at 12:05
      Permalink

      Hi MIke,
      I don’t see the reason why it would break.
      The same way you can give your WordPress a custom prefix on the initial instalation, if you change the value correctly, WordPress will know what your prefix is on every moment.

    • October 30, 2014 at 16:40
      Permalink

      Thanks, Lucy.

      It makes sense.

Leave a Reply

Your email address will not be published. Required fields are marked *