The main reason to change the prefix of the database in different installations of WordPress is to protect your WordPress database from hackers or spammers.To protect or secure your WordPress database, it is good to change its prefix to unique other keywords.
When you are installing a WordPress, you will get the option for changing the database default prefix to another one. But if you have not changed the prefix at installation time, you can change by following steps.
NOTE:Before you continue with following steps, make sure you take backup your database.
STEP 1:Edit wp-config.php
wp_ to the new more secure table prefix.
$table_prefix = "wp_"; //to $table_prefix = "cd1wp_";
Step 2: Change all WordPress table names
Next, Go to WordPress database and apply rename query to database tables to change the prefix of all tables. To rename one table at a time.
Here are Rename queries to rename the 11 tables of wordpress:
Rename table wp_commentmeta to cd1wp_commentmeta; Rename table wp_comments to cd1wp_comments; Rename table wp_links to cd1wp_links; Rename table wp_options to cd1wp_options; Rename table wp_postmeta to cd1wp_postmeta; Rename table wp_posts to cd1wp_posts; Rename table wp_terms to cd1wp_terms; Rename table wp_term_relationships to cd1wp_term_relationships; Rename table wp_term_taxonomy to cd1wp_term_taxonomy; Rename table wp_usermeta to cd1wp_usermeta; Rename table wp_users to cd1wp_users;
If there are other tables from plugins or other things then also rename those tables.
Step 3: UPDATE other Entries in tables
There will be some fields in the options and user meta tables which use wp_as a prefix. so You have to change them as well.
By executing the following query, you will get one row in the table so replace existing old prefix to new prefix.
SELECT * FROM cd1wp_options WHERE option_name LIKE 'wp_user_roles';
NOTE: If you fail to change above prefix, you will not be able to log in afterwards with WordPress.
Finally, execute the following query, you will get some fields which use wp_ as a prefix. so You have to change them from old prefix to new prefix.Don’t miss any records from the table.
SELECT * FROM cd1wp_options WHERE meta_key LIKE "%wp_%";
That is it, Now Test your WordPress site and to make sure everything works fine.