How To Change WordPress Table Prefix

Changing the prefix of your WordPress tables will add an extra layer of security to your site and is not at all difficult to do. Whenever I install WordPress I do so manually via FTP but many users prefer to use an automated script like Fantastico. While convenient, the problem with Fantastico is that it uses the wp_ prefix as a default value - something all of the bad guys know and can attempt to exploit by targeting the wp_options table. While there are a number of plugins that will do the trick I'll show you how to do it manually.

Backup Your Database
This should be your first step. Whenever interacting directly with your database via a tool like phpMyAdmin always backup your database. It can save you much grief later.

Edit the wp-config file
Open the wp-config.php file in a plain text editor and at or about Line 57 you will see...

$table_prefix = 'wp_';

change that to something a bit more obscure like...

$table_prefix = '6EW6xEjuC_';

It's important to note you can only use letters, numbers and underscores. Once complete put the file away as we are finished with it.

Rename Your Tables
This is the fun part. Don't worry, it's an easy procedure. Fire up phpMyAdmin and select your database. Click on the SQL Query icon to launch a new window. See image below.

query

A default installation of WordPress will have 10 tables. Your install may have more depending on what plugins you use but any additional tables will also have to be renamed.

When you click the SQL Query icon a new window will open. In that window enter the command to rename your tables one at a time. This is the data you need to change...

Rename table wp_comments to 6EW6xEjuC_comments;
Rename table wp_links to 6EW6xEjuC_links;
Rename table wp_options to 6EW6xEjuC_options;
Rename table wp_postmeta to 6EW6xEjuC_postmeta;
Rename table wp_posts to 6EW6xEjuC_posts;
Rename table wp_terms to 6EW6xEjuC_terms;
Rename table wp_term_relationships to 6EW6xEjuC_term_relationships;
Rename table wp_term_taxonomy to 6EW6xEjuC_term_taxonomy;
Rename table wp_usermeta to 6EW6xEjuC_usermeta;
Rename table wp_users to 6EW6xEjuC_users;

For instance, click the SQL Query icon to launch a new window. In that window enter...

Rename table wp_comments to 6EW6xEjuC_comments;

then click Go. You will see the newly renamed table. See image below. (click to enlarge)

enter_query

Do this one at a time until all tables have been renamed.

Edit wp_options
You now need to edit some data in the wp_options table which should actually now be called 6EW6xEjuC_options. Select the 6EW6xEjuC_options table and click the Browse icon. See image below. (click to enlarge)

browse_icon

After clicking the Browse icon you will see a new screen. Under the option_name heading at the top, search for wp_user_roles and change it to 6EW6xEjuC_user_roles. See image below. (click to enlarge)

user_roles

Referencing the image above, click the Pencil icon in the wp_user_roles row. You will see a new screen. See image below. (click to enlarge)

change_user_roles

Edit wp_usermeta
This is the final step. Change the data contained within the wp_usermeta table which should now be called 6ew6xejuc_usermeta. Click the Browse icon next to the 6ew6xejuc_usermeta table. See image below. (click to enlarge)

user_meta

After clicking the Browse icon you will see a screen similar to the one below. (click to enlarge)

change_usermeta

Referencing the above image, search under the meta_key heading and change all values starting with the old wp_ prefix. For instance, in the above image you want to change wp_capabilities to 6EW6xEjuC_capabilities and wp_user_level to 6EW6xEjuC_user_level. You do so by clicking the Pencil icon in the appropriate row. It's important to note your install may have more data than is shown above. If so, you need to change that as well. The example I'm using is a default, no-frills install.

Clicking the Pencil icon in the wp_capabilities row will bring up the screen below. (click to enlarge)

change_wp_capabilities

Do this for each applicable row until done. That's it.

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. You can also find him at his other blog LenKutchma.com

3 Responses to “How To Change WordPress Table Prefix”

  1. [...] For a more detailed walk-through, checkout wpcanada.ca. [...]

  2. For WordPress 3.0, there are 3 extra metakeys that need to be changed in the usermeta table.

    Those are:

    - wp_dashboard_quick_press_last_post_id
    - wp_user-settings
    - wp_user-settings-time

    Thanks for the thorough article, it was very useful :)
    Theme Digital´s last blog ..OPAtheme – Magazine &amp Portfolio WordPress ThemeMy ComLuv Profile

Leave a Reply

CommentLuv Enabled