How to change WordPress table prefix

To enhance your WordPress security, it is preferred if the default prefix is changed to something that is not difficult to guess.  This will prevent malicious users from accessing your website and causing problems.  The following are some things you need to do to change the prefix. As always, a backup is advisable before making any changes.

1. Choose your prefix. It should be hard to guess.  Something random and hard to guess like ko220pvm would work well.

1. Rename tables

Use phpMyAdmin and select the appropriate database that is used for your WordPress website.  Either manually rename all the tables or use the following script to change them.

Rename table wp_commentmeta to ko220pvm_commentmeta;
Rename table wp_comments to ko220pvm_comments;
Rename table wp_links to ko220pvm_links;
Rename table wp_options to ko220pvm_options;
Rename table wp_postmeta to ko220pvm_postmeta;
Rename table wp_posts to ko220pvm_posts;
Rename table wp_terms to ko220pvm_terms;
Rename table wp_term_relationships to ko220pvm_term_relationships;
Rename table wp_term_taxonomy to ko220pvm_term_taxonomy;
Rename table wp_usermeta to ko220pvm_usermeta;
Rename table wp_users to ko220pvm_users;

2. The Options Table.

To get a list of rows that need need to be changed, use the following SQL

SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE '%wp_%'

Once you get the list, edit them one by one and change the wp_prefix to the ko220pvm_ prefix

3. UserMeta Table

Similarly, use the following SQL to get the rows that need to be changed.

SELECT * FROM `wp_a123456_usermeta` WHERE `meta_key` LIKE '%wp_%'

One by one, update any wp_prefix to the new ko220pvm_ prefix.

4. Update wp-config.php file

On the root folder where WordPress is installed, edit the wp-config.php file.

Change the $table_prefix = ‘wp_’; to $table_prefix = ‘ko220pvm_’;

5. Test the site

Everything should be working as usual.