The default wonderful 5-minute installation of wordpress keeps the prefix of “wp_” for all its tables. Now why does anybody wants to change the default prefix?
There are 2 reasons I can think of:
- The first and foremost is security. Since the default table prefix is world renowned, changing it will put a first level of defense against any vulnerability or a malicious user trying to execute a rogue code.
- Each wordpress installation takes in a configuration to tell it which prefix it uses. By keeping the prefix different from each installation, you can host multiple wordpress installations in a single mySQL database (not recommended from large installations).
Here’s the configuration in the wp-config.php that determines what prefix wordpress uses.
1 2 |
// Entry in config.php showing wordpress table prefix used in the installation $table_prefix = ‘wp_’; // Only numbers, letters, and underscores please! |
There are wordpress plugins that can change the table prefix automatically, however, I prefer the manual approach so that I understand the changes that are being made.
I’m putting down the steps that I did more for my own reference in the future.
1. Take a backup
Since you will be changing the table structure, backup the database. Next, take backup of the wordpress home folder. Keep both the database backup and home folder backup together in another folder. You will need these for performing a full restore later, in case something goes wrong.
2. Change the configuration in the wp-config.php file
1 |
$table_prefix = ‘wp_’; |
Change this to a prefix to your liking. I would suggest making this as random as choosing the password.
1 |
$table_prefix = ‘tr1mr1_’ |
3. Change the wordpress tables names
Login to phpMyAdmin and select the wordpress database. Go to the SQL area and enter the command to rename each table. There are many tables that start with wp_, change one table at a time. Below are the list of tables found in my installation, however make sure all your tables are renamed.
1 2 3 4 5 6 7 8 9 10 11 |
Rename table wp_commentmeta to tr1mr1_commentmeta; Rename table wp_comments to tr1mr1_comments; Rename table wp_links to tr1mr1_links; Rename table wp_options to tr1mr1_options; Rename table wp_postmeta to tr1mr1_postmeta; Rename table wp_posts to tr1mr1_posts; Rename table wp_terms to tr1mr1_terms; Rename table wp_term_relationships to tr1mr1_term_relationships; Rename table wp_term_taxonomy to tr1mr1_term_taxonomy; Rename table wp_usermeta to tr1mr1_usermeta; Rename table wp_users to tr1mr1_users; |
4. Edit wp_options table
Next is to change the values in the options table. This table is called tr1mr1_options after the renaming step above.
Browse the table and look for the value called ‘wp_user_role’ under ‘option_name’ column. Change ‘wp_user_roles’ to ‘tr1mr1_user_roles’.
5. Edit wp_user_meta table
Look every row under ‘meta_key’ column in the table tr1mr1_user_meta table, as it is called after the renaming.
Change all keys that start with ‘wp_’ to ‘tr1mr1_’. This may be different in different installations, so make sure you cover all the rows.
Here are some I found.
1 2 |
wp_capabilities to tr1mr1_capabilities wp_usersettings to tr1mr1_usersettings |
6. Test
Done! Now test the installation.
If anything goes wrong, you have a backup to restore and start again. Happy blogging!