How to Change WordPress Database Prefix Safely

Every WordPress installation creates its database tables with the same starting letters: wp_. Your posts live in wp_posts, your settings in wp_options, and your users in wp_users. Because millions of sites share that exact prefix, automated attack scripts know which table names to try first. Changing the prefix makes your database a slightly harder target.
It is also a job that can break your site completely if you rush it. Rename the tables but forget to update the settings file, and WordPress cannot find a single post. Miss the user roles stored inside the database, and nobody can log in as an administrator. This guide shows how to change WordPress database prefix safely without a plugin: the easy method before installing WordPress, and the full method for an existing site, with working SQL examples.
What Is the WordPress Database Prefix?
The database prefix is a short string added to the front of every WordPress table name. A fresh installation creates 11 or 12 tables, and every one of them starts with wp_ by default. The prefix is defined in wp-config.php, in a line that looks like this: $table_prefix = ‘wp_’;
WordPress uses that single setting to build every table name it needs. Change the prefix in wp-config.php and rename the tables to match, and WordPress keeps working exactly as before. The prefix also lets more than one installation share a single database without their tables colliding.
Why Do People Change the Database Prefix?
The main reason is obscurity. Automated bots scan the internet for WordPress sites and try known attacks, including SQL injection attempts that target tables by their default names. If your tables use a custom prefix such as wpx7_, a generic script that assumes wp_posts will fail, because no table with that name exists. It is a small obstacle, but it filters out the laziest automated attacks.
There is also a practical reason. If you manage several WordPress sites in a single database, a distinct prefix for each site keeps the tables organised. See the change as one small layer among many. It costs nothing, it takes twenty minutes, and it removes one easy guess from an attacker’s toolkit. Combined with strong passwords and regular updates, it is a sensible part of a wider routine. On its own, it is not a security strategy.
Is Changing the Prefix Real Security or Just Obscurity?
Here is the honest counterpoint. Many security experts argue that changing the database prefix adds very little real protection. An attacker who can run SQL against your database can list all the table names in seconds, whatever prefix you chose. The official WordPress hardening documentation does not list a prefix change among its essential steps. The WordPress hardening guide shows what the core team recommends.
That does not make the change worthless, but it must never replace the measures that actually protect a site: a strong admin password, two factor authentication, timely updates, and a reliable backup routine. A site with a custom prefix and a weak password is far less secure than a site with the default prefix and a strong password. Change the prefix if you like, but do not let it give you a false sense of safety. First finish our guide to back up your WordPress database without a plugin.
What Should You Do Before You Change the Prefix?
Make a full backup first. You are about to rename every table in the database and edit the file that connects WordPress to it. One mistake can lock you out of the admin area or show a database connection error to every visitor. A backup turns a disaster into a five minute restore, so keep it until the site works perfectly with the new prefix.
- Export a full copy of the database from phpMyAdmin with the Quick method.
- Download a copy of wp-config.php, so you can restore the original prefix line if needed.
- Note down your current prefix exactly, including the trailing underscore, because you will need it in the SQL queries below.
- Pick a new prefix using only letters, numbers, and underscores, for example wpx7_. Keep it short and end it with an underscore.
Method 1: How Do You Change the Prefix Before Installing WordPress?
If you have not installed WordPress yet, changing the prefix takes less than a minute. There are no tables to rename and nothing stored in the database yet, because it is still empty.
Open wp-config.php through File Manager in cPanel or an FTP client. Find the line $table_prefix = ‘wp_’; Replace wp_ with your new prefix, for example $table_prefix = ‘wpx7_’; Save the file and run the WordPress installer as normal. Every table WordPress creates will use your new prefix automatically. If you are still planning the installation, our web hosting guide explains how to choose a plan with a proper database setup, and our staging guide shows how to create a WordPress staging site without a plugin so you can practise safely first.
Method 2: How Do You Change the Prefix on an Existing Site?
For a site that is already running, the change has four steps: edit wp-config.php, rename every table, update the option names in the options table, and update the meta keys in the usermeta table. Miss any one and something breaks, so work through them in order.
Step 1: Edit wp-config.php
Open wp-config.php through File Manager in cPanel and find the line $table_prefix = ‘wp_’; Change wp_ to your new prefix, for example wpx7_, and save the file. Your site will show a database error now, because the tables still carry the old names. That is expected. The next step fixes it.
Step 2: Rename every table in phpMyAdmin
Open phpMyAdmin from cPanel and select your WordPress database from the left sidebar. Click Check All at the bottom of the table list, then open the With selected dropdown and choose Replace table prefix. Enter wp_ in the From field and your new prefix in the To field, then click Go. The official phpMyAdmin documentation explains every tab and option.
If you prefer SQL, run one RENAME TABLE statement per table in the SQL tab:
RENAME TABLE wp_commentmeta TO wpx7_commentmeta;
RENAME TABLE wp_comments TO wpx7_comments;
RENAME TABLE wp_links TO wpx7_links;
RENAME TABLE wp_options TO wpx7_options;
RENAME TABLE wp_postmeta TO wpx7_postmeta;
RENAME TABLE wp_posts TO wpx7_posts;
RENAME TABLE wp_termmeta TO wpx7_termmeta;
RENAME TABLE wp_terms TO wpx7_terms;
RENAME TABLE wp_term_relationships TO wpx7_term_relationships;
RENAME TABLE wp_term_taxonomy TO wpx7_term_taxonomy;
RENAME TABLE wp_usermeta TO wpx7_usermeta;
RENAME TABLE wp_users TO wpx7_users;
Adjust the list to match your own site. Plugins may have added extra tables, and a multisite installation has extra tables for each subsite. Rename every table that starts with the old prefix. A table left behind is invisible to WordPress, so its plugin will behave as if freshly installed.
Step 3: Update the option names in the options table
Renaming the tables is not enough, because a few values stored inside them still contain the old prefix. The options table holds several option names that begin with wp_, most importantly user roles. If you skip this step, every user loses their role and nobody can use the admin area properly. Run this query in the phpMyAdmin SQL tab, replacing wpx7_ with your own new prefix:
UPDATE wpx7_options SET option_name = REPLACE(option_name, 'wp_', 'wpx7_') WHERE option_name LIKE 'wp_%';
The WHERE clause limits the change to option names that start with the old prefix. Only a handful of rows change, but they matter.
Step 4: Update the meta keys in the usermeta table
The same problem exists in the usermeta table, which stores per user settings such as capabilities. The meta keys there also start with the old prefix, and WordPress looks them up using the new prefix after your change. Run this query, again replacing wpx7_ with your own prefix:
UPDATE wpx7_usermeta SET meta_key = REPLACE(meta_key, 'wp_', 'wpx7_') WHERE meta_key LIKE 'wp_%';
This query updates the capability records for every user, which restores admin access after the rename. If you skip it, you can log in but WordPress will treat your account as a subscriber with no admin menus. Some plugins also store the old prefix inside their own settings, so search the options table for remaining rows containing wp_ after the update. Most of them are harmless, such as a stored file path, and changing them can corrupt the data, so do not blindly replace every occurrence. See our guide to WordPress database cleanup without a plugin for more on keeping the database tidy afterwards.
How Do You Test the Site After Changing the Prefix?
Open the homepage and click through several posts and pages. Then log in and confirm that the dashboard loads and your account still shows the administrator role. Create a test post and a test comment, then delete both. If your site uses WooCommerce or a membership plugin, check that products and member pages still work.
If anything looks wrong, do not guess. A blank page usually means a table was missed. Turn on debugging temporarily to see the error message, as explained in our guide to enable WordPress debug mode. A database connection error means the prefix in wp-config.php does not match the renamed tables. If you can log in but have no admin menus, the usermeta update in step 4 was skipped, so run that query again. If the problem resists fixing, restore the backup you made before you started. See our guide to fix the WordPress white screen of death for the same debugging steps.
What Are the Common Mistakes to Avoid?
- Skipping the backup: the one mistake that turns a small error into a lost site.
- Renaming only some tables: every table with the old prefix must be renamed, including plugin tables.
- Forgetting the options and usermeta updates: the tables work, but roles and capabilities break, and admin access disappears.
- Using a hyphen or space in the prefix: only letters, numbers, and underscores are allowed, and the prefix should end with an underscore.
- Editing wp-config.php in a word processor: use a plain text editor or the cPanel File Manager instead.
- Changing the prefix on a live site during peak traffic: do it at a quiet time, and test on a staging copy first.
Frequently Asked Questions
Can I change the WordPress database prefix after installation?
Yes. Edit the $table_prefix line in wp-config.php, rename every table in phpMyAdmin, then update the option names and meta keys that still carry the old prefix. It takes about twenty minutes, and a backup beforehand makes it safe.
Will changing the database prefix break my plugins?
It should not, as long as you rename every table, including plugin tables. Well written plugins read the prefix from WordPress instead of hardcoding wp_, so they follow the new prefix automatically. A plugin that stored the old prefix may need its settings saved again, so test each important plugin after the change.
What is the safest new database prefix to use?
Any short prefix made of letters, numbers, and underscores is safe, as long as it ends with an underscore. Something random such as wpx7_ works well, because it is not guessable. Avoid your site name alone, and never use a hyphen or a space.
Do I need to change the database prefix for security?
No, it is not essential. Security experts debate its value, because an attacker who can run SQL can list your tables regardless of the prefix. It blocks only generic automated attacks. Strong passwords, two factor authentication, updates, and backups protect your site far more, so treat it as an optional extra, not a replacement.
Last updated: November 2026.



