Changing WordPress Database table prefix

Change WordPress Table Prefix

There may be a time after you have completed your setup that you realize you need to change the default WordPress database ‘table_prefix’ for your WordPress database (from the default ‘wp_’ or cryptic random string provided by Installatron) to something more specific or specialized.

In any case, there is no need to worry, it’s a simple three step process if you do it manually; or you can use a plugin (but this is definitely not my preference).

Step 1: Change the database table prefix in wp-config file

  1. Login to your hosting provider and access the file manager (methods to accomplish this vary depending your host and their tools)
  2. Navigate to the ‘public_html’ folder, locate the ‘wp-config.php’ file and edit the file
  3. Locate the following: $table_prefix = “wp_”;
  4. Replace ‘wp_’ with the prefix of your choice (i.e. ‘cpwd_’)
  5. Save the updated wp-config.php

Step 2: Change database table prefix in MySQL/MariaDB

  1. Open your database in phpMyAdmin.
  2. Click on the database name in the menu to the left to unfold all tables.
  3. Select all tables that start with wp_; there should be 12 in total (if no additional plugins are installed).
  4. Click “With selected” to open the drop-down menu and select “Replace table prefix”.
phpmyadmin replace table prefix
  1. Type in wp_ in the From-field, and the new name in the To-field (Keeping with our use case, I will use cpwd_).
  2. Click Continue to make the change

Step 3: Replace all references to old database table prefix

  1. Click on the SQL tab in the menu at the top of the screen.
  2. Copy and paste in the following commands:
update NEWPREFIX_usermeta set meta_key = 'NEWPREFIX_capabilities' where meta_key = 'OLDPREFIX_capabilities';
update NEWPREFIX_usermeta set meta_key = 'NEWPREFIX_user_level' where meta_key = 'OLDPREFIX_user_level';
update NEWPREFIX_usermeta set meta_key = 'NEWPREFIX_autosave_draft_ids' where meta_key = 'OLDPREFIX_autosave_draft_ids';
update NEWPREFIX_options set option_name = 'NEWPREFIX_user_roles' where option_name = 'OLDPREFIX_user_roles';
  1. Replace OLDPREFIX and NEWPREFIX, with your own old and new prefix. In keeping with our example, we are going to replace the default wp_ with cpwd_:
update cpwd_usermeta set meta_key = 'cpwd_capabilities' where meta_key = 'wp_capabilities';
update cpwd_usermeta set meta_key = 'cpwd_user_level' where meta_key = 'wp_user_level';
update cpwd_usermeta set meta_key = 'cpwd_autosave_draft_ids' where meta_key = 'wp_autosave_draft_ids';
update cpwd_options set option_name = 'cpwd_user_roles' where option_name = 'wp_user_roles';
  1. Click on Go to run the commands and complete the change.

And that’s it, you have successfully changed your WordPress database table prefix!


If you found this article helpful, we hope you will share it and provide feedback using the comments form below…

Leave a Reply

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