Changing The WordPress Table Prefix

A warm WordPress Wednesday welcome! 🙂

Today I embarked on a journey into the unknown. In my attempt to perfect my naming conventions, I decided to change my table prefix… after installing WordPress. (Don’t worry, it wasn’t “live;” I just didn’t want to redo any steps.)
Okay, so the story begins with little impatient me, setting up my new install and straight-up forgetting to make my own table prefix. So now I will share with you how I changed them after the fact.

Changing Your WordPress Table Prefix After Install
First, I opened my wp-config.php file and changed the prefix there. Easy peasy. Keep in mind, if you visit the front end of your site after editing wp-config but before making changes in the database, it will appear as though you are setting up your WordPress site again. My advice: Don’t bother looking at the front end. Looking at the front end while working in the database will always make you ill.

Next, login to your cPanel/Plesk/admin area. Navigate to phpMyAdmin and navigate to your WordPress database. (If you did a one-click install through your hosting provider, you may not know the name of your database, but it shouldn’t be hard to find if you have only installed WordPress once.) As of WordPress 3.8, there are 11 tables. Each table will need to be renamed. If you are comfortable with SQL, you can write 11 commands to rename your tables following this structure:

RENAME table `wp_commentmeta` TO `new_commentmeta`;

(Where “new” would be your newly chosen prefix that you put in wp-config.) If you aren’t as familiar with SQL, you can open each table individually, click on the Operations tab, and there is a textbox for “Rename table to.” Simply swap out the “wp” with your new prefix.

Once the tables are renamed, we’re done, right? That’s what I thought at least! Then I tried to re-login and every page said I didn’t have sufficient permissions to view the page. My first thought was to go to my usermeta and check my capabilities… WRONG! It turns out, there’s this vitally important option called wp_user_roles and it’s nestled in your options table.

Querying for %wp_% in WordPress Options Table

All you have to do is change that darn “wp” one last time (all other instances of “wp_” in the tables corrected themselves after the change in wp_config).

WordPress Options wp_user_roles

Now you can check out that awesome site you created, purposely broke, and then fixed!

I hope this information was helpful in your quest for beautiful table names. If not, let me know what you’d rather read about for next WordPress Wednesday!