How to Change the WordPress Table Prefix

Assuming my current WordPress prefix was “wp_” and I wanted to change it to “banana_”, then I would do the following…

Take a backup of your database and file system. Remember, if you screw up and trash your blog you will thank yourself for the extra time you spent doing this!

Amend the “$table_prefix” setting in the “wp-config.php” file.

$table_prefix = 'banana_'; // Only numbers, letters, and underscores please!

Rename all the tables, swapping the “wp_” prefix with “banana_”. For example, the following statement would rename the “wp_comments” table to “banana_comments”.

RENAME TABLE wp_comments TO banana_comments

Perform the following updates.

UPDATE banana_options SET option_name = 'banana_user_roles' WHERE option_name = 'wp_user_roles'
UPDATE banana_usermeta SET meta_key = 'banana_capabilities' WHERE meta_key = 'wp_capabilities'
UPDATE banana_usermeta SET meta_key = 'banana_user_level' WHERE meta_key = 'wp_user_level'
UPDATE banana_usermeta SET meta_key = 'banana_autosave_draft_ids' WHERE meta_key = 'wp_autosave_draft_ids'

If you don’t do these updates, the blog will work, but when you try to access the admin site you will be greeted with a message saying,

You do not have sufficient permissions to access this page.

That’s it!

Cheers

Tim…