Nexcess Logo

WordPress database setup — changing the database prefix

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
January 23, 2023

For WordPress, the default database prefix, specifically referred to as the database table prefix is wp_, but we recommend changing it to increase the security of your overall WordPress database setup.

The reason for this recommended change is that all your user login details are stored in your database, making your WordPress tables very popular targets for hackers.

Changing the database table prefix makes it harder for malicious database-focused attacks to succeed. The table prefix change will make the site more secure, hardening it to database-based attacks.

About changing the database prefix

In the simplest terms, changing the database prefix as discussed in this article will help fortify your overall application security.

The reason is that the user access details are stored in the database, making your WordPress application an easier target.

Altering the default database table prefix will be an unexpected twist for the hackers attempting to gain access.

Your default WordPress database table prefix can be changed in a straightforward manner, and this article will help you accomplish this end.

Steps for changing the default WordPress database setup

1. Change the table prefix in wp-config.php

Regarding necessary changes to the wp-config.php file, let's review the details involved. Those are covered below.

Access the wp-config.php file for your website over FTP or SSH.

Locate the wp-config.php file and open the file in editing mode.

Locate the following entry within the wp-config.php file, which starts out with the default WordPress database table prefix:

$table_prefix = 'wp_';

Replace wp_ with something else. In this example below, we have replaced it with the cmj_ character string:

$table_prefix = 'cmj_';

Save the changes in the wp-config.php file.

2. Change the table prefix in the database

The free tool, phpMyAdmin, is a database utility that allows the management of MySQL or MariaDB databases. Using phpMyAdmin, any activities like creation or modification of databases, running of queries, and user account management tasks are handled easily — even for a non-techie person.

The phpMyAdmin interface can be accessed through SiteWorx (non-cloud) or your Nexcess Client Portal. Therefore, how you access phpMyAdmin depends on the type of Nexcess plan that you have. Because we have provided the phpMyAdmin as a management tool, Nexcess makes efficient to manage your databases from the Nexcess Client Portal.

Access the tool phpMyAdmin and select the respective database for the application.

Click on the database name in the menu to the left to unfold all tables.

Select all tables that start with the wp_ character string. You should have 12 table selected in total.

With those tables selected, open the dropdown menu and select Replace Table Prefix. Replace the table prefix as needed.

Type in wp_ in the From field, and the new database table prefix in the To field, which will be cmj_ in our example.

Click Continue to make the change.

3. Change all references to include the new database table prefix

To complete the table prefix change, you will need to replace old table prefix with the new table prefix in the settings that are stored in your database.

Open the SQL tab.

Get started with managed hosting from Nexcess

We make great content and commerce platforms better to build on

Execute the following commands in the SQL tab of the phpMyAdmin utility or via the MySQL/MariaDB command line (pseudo code example):

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';

Real example

We looked at the pseudo code above. Now let's look at a real example. As part of your new WordPress database setup, replace the old default wp_ prefix with your new one.

In the real example below, we are replacing wp_ with cmj_ as our new database table prefix. The SQL command line would look as follows:

update cmj_usermeta set meta_key = 'cmj_capabilities' where meta_key = 'wp_capabilities';

update cmj_usermeta set meta_key = 'cmj_user_level' where meta_key = 'wp_user_level';

update cmj_usermeta set meta_key = 'cmj_autosave_draft_ids' where meta_key = 'wp_autosave_draft_ids';

update cmj_options set option_name = 'cmj_user_roles' where option_name = 'wp_user_roles';

Once the above steps are complete, click Go to run the commands and complete the change. You have set the new custom database table prefix for your site's WordPress database.

All is well and good now. The prefix on your WordPress database tables has been successfully changed. Thus, the custom prefix setup is completed, giving you an extra layer of security.

Empowering web hosting admins

Using the Nexcess Client Portal you can control WordPress updates, manage domain name changes, and push a new site live.

From downloading access and error logs to managing web hosting teams and users — and so much more — Nexcess empowers admins.

Not a Nexcess customer yet?

Managed WordPress and WooCommerce from Nexcess make site management less burdensome.

We love to make web hosting more manageable so you can focus on your other business priorities.

Check out our plans to get started today.

Recent articles

Related articles

Christy Joy
Christy Joy

Christy Joy has over five years of professional experience as a Senior Server & System Administrator and has enjoyed working with technology platforms at scale her entire career.

Her hobbies and interests include blogging focused on her ample technology insights gained over an accomplished career, traveling, making new friends, listening to music, artistic works, and social networking. To fly high without any limitations is the dream, Christy reminds us all.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.