METHOD 1: CHANGING THE DEFAULT DATABASE TABLE PREFIX BEFOREINSTALLING WORDPRESSThe easiest way to change the WordPress database prefix is before installing the CMS to your website. Before you install WordPress, navigate to the wp-config.php file and scroll down until you find $table_prefix = ‘wp_’;.
METHOD 2: CHANGING THE DEFAULT DATABASE TABLE PREFIX AFTERINSTALLING WORDPRESSIf you’ve already installed the WordPress CMS to your website, you can change the default database prefix by following these steps:
STEP 1: BEFORE YOU BEGINSince we’ll be making changes to the wp-config.php file, it is highly recommended that you create a full backup of your WordPress database before changing the table prefix. If you get a lot of traffic on your website then it would be a good idea to redirect your site’s visitors to a temporary maintenance page.
STEP 2: CHANGE THE DEFAULT TABLE PREFIXOpen up your wp-config.php file located in your WordPress root directory. Scroll down until you find the table prefix line i.e. $table_prefix = ‘wp_’;. Change the database prefix from ‘wp_’to something random like ’wp_a1b2c3d4’.
STEP 3: RENAME ALL WORDPRESS DATABASE TABLESNext, navigate to your WordPress database through phpMyAdmin and rename all of the table prefixes to the one you specified in your wp-config.php file. As we mentioned before, there are a total of 12 default WordPress tables. One way to do that is to rename each table manually. But that take a lot of time. So, to make things faster, here’s a list of SQL commands that you can run to rename all 12 of the default WordPress tables: If you have plugins installed on your WordPress website then chances are you might have a few extra tables in your database. If so, simply rename them, too – either manually or by modifying one of the SQL commands given above. In order to minimize the risk of a hacking attempt, it’s a good idea to rename all of your WordPress database tables that begin with the default prefix to something random.
STEP 4: MODIFY THE OPTIONS TABLENext, we need to search the options table for any instances of the old, default prefix so we can replace them, too. Here’s an SQL query to save you some time:
SELECT * FROM `wp_ a1b2c3d4_options` WHERE `option_name` LIKE '%wp_%'
STEP 5: MODIFY THE USERMETA TABLESimilarly, search the usermeta table for any instances of the old prefix so that you can replace it with the new prefix. Here’s an SQL query to help you out:
SELECT * FROM `wp_ a1b2c3d4_usermeta` WHERE `meta_key` LIKE ‘%wp_%’