Change Table Prefix For Self Hosted WordPress

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:

  1. 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.
  2. 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.

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

Change this to a prefix to your liking. I would suggest making this as random as choosing the password.


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.

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.

6. Test

Done! Now test the installation.

If anything goes wrong, you have a backup to restore and start again. Happy blogging!

Source Code Highlighting in Windows Live Writer

When I first started posting code to the site, it took me a while to format it correctly, until I realized there are many plugins available for automatically doing this. When I was using a self hosted WordPress site, I could install plugins or insert a custom css to format the code block like I want, but I soon found out that was not the case for WordPress.com sites as there is no control to install new plugins or change the CSS.

However WordPress.com supports a short code for highlighting sourcecode.

A quick search for Windows Live Writer plugins that support this short code turned up many. I tried a few of the code highlighters and finally settled on the one posted by Rich Hewlett called WLW Code Plugin.

A C# code would look like below:

UPDATE: I have now stopped using this plugin as I prefer the plugins that use the ‘<pre>’ tag which is more standard and backward compatible.