How to Add or Change Prefixes to WordPress Database Tables via phpMyAdmin


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.php file 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.

  1. Log in to your cPanel account.

  2. Navigate to the Databases section and click on phpMyAdmin.

  3. Select your WordPress database from the left-hand sidebar.

  4. 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.

  1. A dialogue box will appear:

    • From: wp_ (or your current prefix)

    • To: yournewprefix_ (e.g., secure99_)

  2. Click Continue

If adding a prefix:

In the dropdown menu next to the check all box (labelled "With selected:"), choose Add prefix to table.

  1.  A dialogue box will appear:
    • Add prefix: e.g.yournewprefix_ 
  2. 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.

  1. In cPanel, open File Manager.

  2. Locate the wp-config.php file in your site's root directory.

  3. Right-click and select Edit.

  4. Find the line that looks like this:

    $table_prefix = 'wp_';

  5. Change 'wp_' to your new prefix:

    $table_prefix = 'yournewprefix_';

  6. 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.

  1. Go back to phpMyAdmin and select your database.

  2. Click the SQL tab at the top.

  3. 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.

SQL
 
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.

SQL
 
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.


Was this answer helpful?

Still need help?

Our friendly support team are ready to offer assistance with any issues you may be encountering.
Click the button below to open a ticket:
Open Ticket

 WordPress Hosting

Fast hosting for WordPress
Experience the best in Australian WordPress hosting with lightning fast servers, built-in caching, and performance tools.

 Build Your Website

Sitejet Hosting
Build your site fast with a drag and drop editor with no coding required. 140+ quality, templates to get you started.

 Register Domains

It all starts with your domain name
Find the perfect domain and register now with our competitive pricing on all extensions.

 Web Hosting

Fast, local, secure hosting
Full featured hosting on cPanel with multiple server locations around the country.
« Back