Back to Top

How To Change Database PREFIX in WordPress

Basically, WordPress had a default database prefix wp_ and I strongly recommend to change default prefix to the other word.

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

First of all,Open wp-config.php file which can be found in the WordPress root directory and replace the default prefix

wp_ to the new more secure table prefix.

$table_prefix = "wp_";
$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.


Post Autosave Interval in WordPress
To add new URL rewrite rule in WordPress
Auto-tagging in WordPress

I hope you have enjoyed this tutorial. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (1)

  1. […] for changing the database default prefix(wp_) to other one. few days ago, I have posted about “To Change Database PREFIX in WordPress” which is about to change database prefix manually after installation and which is somewhat […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Replace function in MySQL

Posted on 7 years ago


How to manage Session in WordPress

Posted on 6 years ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 4 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 5 years ago