How to change WordPress database table prefix?

If you have a wordpress website, you will see the default table prefix as 'wp_;'. However, some users may require to change the prefix due to various reasons. Also, if your table prefix is 'wp_'; it is easy for hackers to identify and attack your Wordpress. If you change the prefix, it can be hard for them to break in.

Please refer to the following steps to change the database table prefix for your Wordpress. 

  1. Open your File Manager, locate the file wp-config.php and open it.

  2. Locate a line with the following entry. 

    $table_prefix = 'wp_';
  3. Replace the table prefix from 'wp_' to your required one. Here we have changed it to demo_.

    $table_prefix = 'demo_';
  4. Open the phpMyAdmin and go to your Wordpress database. Check all the tables and click on replace table prefix option. Click on continue, and it will change all the existing table prefixes to demo_.

  5. Wordpress may use the old table prefix from some of the settings stored in the database. You can make the below changes to replace the new prefix. 

  6. Inside phpMyAdmin, click on the SQL button. 

  7. Copy-paste the following line and replace the NEWPREFIX and OLDPREFIX as per your requirement. We have used demo_ as a new prefix. 

    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';
  8. Once you are ready with the replacement, click on the Go button. 

    You have successfully change the Wordpress Database table prefix.

Related Articles

How to Upload a WordPress theme?

Sometimes you are required to upload and install a WordPress theme manually, especially when you...

How to fix an error SSL certificate problem, verify that the CA cert is OK?

You may encounter this error while performing actions like theme/plugins installation or...

How to fix 403 forbidden error in WordPress?

What is 403 FORBIDDEN ERROR IN WORDPRESS?  The 403 Forbidden error code is shown to a web...


While troubleshooting any WordPress issues, you are asked to deactivate all plugins and activate...

  • 0 Users Found This Useful

Was this answer helpful?