Sunday, October 20, 2013

Change prefix of the database

Step1. Backup your Database
Create a backup copy of your WordPress database from your phpMyAdmin Web interface using the Export function. How to do that?
Log into your phpMyAdmin and select your WordPress database.
Click on the "Export" tab at the top.
Follow the instructions as shown in the image below.

Step2. Change all your WordPress Table Names
In your phpMyAdmin and from your WordPress database, select the SQL tab and enter the following commands to rename all your 11 tables at once and click "GO". Depending on what plugins you installed, you might have more tables starting with “wp_” prefix, that need editing, make sure to rename all tables.
For instance, let´s say you want to replace wp_ with wpr12f_, then Run the following SQLcommands as shown in the code and image below.
1
2
3
4
5
6
7
8
9
10
11
Rename table wp_commentmeta TO wpr12f_commentmeta;
Rename table wp_comments TO wpr12f_comments;
Rename table wp_links TO wpr12f_links;
Rename table wp_options TO wpr12f_options;
Rename table wp_postmeta TO wpr12f_postmeta;
Rename table wp_posts TO wpr12f_posts;
Rename table wp_terms TO wpr12f_terms;
Rename table wp_term_relationships TO wpr12f_term_relationships;
Rename table wp_term_taxonomy TO wpr12f_term_taxonomy;
Rename table wp_usermeta TO wpr12f_usermeta;
Rename table wp_users TO wpr12f_users;

If you can´t see the new table names, either refresh the page or logout from phpMyAfmin and log back in.
In my case single quotes around table names cause syntax error. In your case you might need to add single quotes.
Step3. Edit the _options Table
Now search the wpr12f_options table for any instances of the old prefix (wp_). To do this, select the wpr12f_options table and click on the “Browse” tab. You will see all the records stored in that table. Search under the option_name field and changewp_user_roles along with any other records (starting with wp_) created by plugins, custom scripts, and probably others. Rename any options that begin with wp_ to the new prefix. You can change each record by clicking on the "Edit" pencil image for that record.Make sure not to miss any records.

You can also execute a SQL command to find the records that need editing:
1
SELECT * FROM wpr12f_options WHERE option_name LIKE 'wp_%';
See the image below:

Step4. Edit the _usermeta Table
Now do the same thing for the wpr12f_usermeta table, search for all instances of the oldwp_ prefix. Select the wpr12f_usermeta table and then click on the “Browse” tab. Search under the meta_key field all records that start with the old wp_ prefix. Edit each record it by clicking on the "Edit" pencil image for that record. Make sure not to miss any records.

Do NOT edit any records starting with the prefix _wp_, but only records staring with the prefix wp_
You can also execute a SQL command here to find the records that needs editing:
1
SELECT * FROM wpr12f_usermeta WHERE meta_key LIKE 'wp_%';
See the image below:

Step5. Edit Your wp-config.php File
Now open your wp-config.php file and change your table prefix in from wp_ to whatever prefix you decide to use (wpr12f_ for this tutorial). Save and upload it to your server, as shown in the following code snippet:
1
2
3
4
5
6
7
8
/**
 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
//Rename the table prefix variable from the default 'wp_' to a new hard to
//guess and more secure prefix.
$table_prefix  = 'wpr12f_';
Step6. Test your WordPress Website
Now vigorously test your Website for proper functionality. Test your plugins, contact form, search field, posts, pages, comments, administration area, and anything else you can think of. If your Website is working as before, then the tables prefix change is a success.
Step7. Do Another Backup
Go ahead and do another backup of your database as a good and wise habit.


0 comments:

Post a Comment

    Blogger news

    Blogroll

    About