Changing or adding a prefix to your WordPress database tables is a common security practice. By default, WordPress uses the wp_ prefix. Changing this to something unique, like db7_ or site_, makes it significantly harder for automated SQL injection scripts to guess your table names.
⚠️ Important Prerequisites
Before making any changes to your database, you must perform the following:
-
Backup your database: Create an export of your current database via cPanel or a plugin.
-
Edit permissions: Ensure you have access to your site’s
wp-config.phpfile via File Manager or FTP.
Step 1: Update the Table Names in phpMyAdmin
The first step is to physically rename the tables in the database.
-
Log in to your cPanel account.
-
Navigate to the Databases section and click on phpMyAdmin.
-
Select your WordPress database from the left-hand sidebar.
-
Scroll to the bottom of the table list and check the Check All box.
If changing the prefix:
In the dropdown menu next to the check all box (labelled "With selected:"), choose Replace table prefix.
-
A dialogue box will appear:
-
From:
wp_(or your current prefix) -
To:
yournewprefix_(e.g.,secure99_)
-
-
Click Continue
If adding a prefix:
In the dropdown menu next to the check all box (labelled "With selected:"), choose Add prefix to table.
- A dialogue box will appear:
- Add prefix:
e.g.yournewprefix_
- Add prefix:
-
Click Continue
Step 2: Update the wp-config.php File
WordPress will now show a "Error Establishing a Database Connection" because it is still looking for the old wp_ prefix.
-
In cPanel, open File Manager.
-
Locate the
wp-config.phpfile in your site's root directory. -
Right-click and select Edit.
-
Find the line that looks like this:
$table_prefix = 'wp_'; -
Change
'wp_'to your new prefix:$table_prefix = 'yournewprefix_'; -
Save Changes.
Step 3: Update the options and usermeta Tables
WordPress stores the prefix inside two specific tables. If you don't update these, you may be locked out of your admin dashboard.
-
Go back to phpMyAdmin and select your database.
-
Click the SQL tab at the top.
-
Run the following queries one by one (replace
yournewprefix_with your actual new prefix):
Update the Options Table
This query finds any references to the old prefix in the settings.
UPDATE `yournewprefix_options` SET option_name = REPLACE(option_name, 'wp_', 'yournewprefix_') WHERE option_name LIKE 'wp_%';
Update the Usermeta Table
This query updates user permissions so WordPress recognises you as an administrator.
UPDATE `yournewprefix_usermeta` SET meta_key = REPLACE(meta_key, 'wp_', 'yournewprefix_') WHERE meta_key LIKE 'wp_%';
Step 4: Verification
-
Clear your browser cache.
-
Log in to your WordPress admin dashboard (
yourdomain.com/wp-admin). -
Navigate through your posts and settings to ensure everything is functioning correctly.
- Activate Cache and Security plugins
Note: If you use security or caching plugins, you may need to reset their settings as they occasionally hardcode table names into their own configuration files.