Database navigation guide
Change the WordPress table prefix safely.
Renaming wp_ to something else touches more than the table names — serialized data and per-user meta keys embed the prefix too, and a naive find-and-replace corrupts both.
A non-default prefix is not meaningful security on its own — reconsider whether this is worth doing before you start.
A raw SQL REPLACE() breaks any serialized value whose byte-length no longer matches after the edit.
Tables, wp-config.php, and specific wp_usermeta keys all embed the prefix — miss one and the site breaks in a different way.
Why people actually do this
Two reasons hold up. Consolidating several WordPress installs into one shared database, where table names would otherwise collide, is a real and common one. A hosting or compliance requirement that mandates a specific naming scheme is another. "Security" on its own is weaker than it sounds — a distinctive prefix is not meaningful defense in depth by itself, since anyone with database access already has everything the prefix was supposedly hiding. WordPress's own hardening guidance treats it as a minor, optional step, not a primary control. Put the effort into file permissions, account hygiene, and staying current instead, and only rename the prefix when you have one of the two real reasons above.
What actually has to change
A plain RENAME TABLE handles the tables themselves and nothing else. Three more places embed the prefix and are easy to miss:
| Component | What changes | Risk if missed |
|---|---|---|
Tables | Each oldprefix_* table renamed to newprefix_* | WordPress can't find its own data at all |
wp-config.php | The $table_prefix constant updated to match | WordPress keeps querying the old (now-renamed) table names |
wp_usermeta keys | Exact-match keys like wp_capabilities and wp_user_level renamed to the new prefix | Every user silently loses their role and capabilities |
Serialized values | Any serialized array or object containing the old prefix as a substring | Corrupted on a byte-length mismatch from a naive replace, not just unchanged |
A safe order of operations
- 01Back up, and enable maintenance mode.
Verify the backup actually restores before you rely on it — this is exactly the kind of change where you'll want that proof.
- 02Rename each table.
RENAME TABLE oldprefix_posts TO newprefix_posts;for every table — a plain rename is safe here, since a table name isn't serialized data. - 03Update
wp-config.php.Set
$table_prefixto the new value. WordPress reads this on every request, so an unmatched prefix here undoes step 02 immediately. - 04Fix the exact-match usermeta keys.
A plain
UPDATEonmeta_keyvalues likeoldprefix_capabilitiesandoldprefix_user_levelis safe — these are fixed strings, not serialized blobs. - 05Run a serialization-aware search-replace for anything left over.
WP-CLI's
wp search-replaceis built specifically to rewrite strings inside serialized PHP data without corrupting it — use it to catch any remaining reference to the old prefix, not a raw SQLREPLACE(). - 06Test exhaustively before going live.
Confirm login, every user's role and capabilities, and plugin functionality on a staging copy first. On multisite, repeat this for every subsite's numbered tables, not only the shared ones.
The statements, ready to adapt
Replace oldprefix_ and newprefix_ everywhere below, and run them against a backup-tested copy first. List every table carrying the old prefix with SHOW TABLES LIKE 'oldprefix\_%'; — plugins add their own, and each one needs renaming too. The core tables of a single site:
RENAME TABLE oldprefix_commentmeta TO newprefix_commentmeta, oldprefix_comments TO newprefix_comments, oldprefix_links TO newprefix_links, oldprefix_options TO newprefix_options, oldprefix_postmeta TO newprefix_postmeta, oldprefix_posts TO newprefix_posts, oldprefix_term_relationships TO newprefix_term_relationships, oldprefix_term_taxonomy TO newprefix_term_taxonomy, oldprefix_termmeta TO newprefix_termmeta, oldprefix_terms TO newprefix_terms, oldprefix_usermeta TO newprefix_usermeta, oldprefix_users TO newprefix_users;
Then the keys that store the prefix as part of their name. These are plain strings, so a direct UPDATE is safe — wp_capabilities and wp_user_level in user meta, wp_user_roles in options, plus a few per-user settings keys that follow the same pattern:
UPDATE newprefix_usermeta
SET meta_key = CONCAT('newprefix_', SUBSTRING(meta_key, CHAR_LENGTH('oldprefix_') + 1))
WHERE meta_key LIKE 'oldprefix\_%';
UPDATE newprefix_options
SET option_name = 'newprefix_user_roles'
WHERE option_name = 'oldprefix_user_roles';
Finally, look for anything else that still mentions the old prefix — a dry run reports every match, table by table, and changes nothing:
wp search-replace 'oldprefix_' 'newprefix_' --all-tables --dry-run
Read that report before running it for real. With the default wp_ prefix in particular, the string also appears in ordinary content and plugin settings — wp_mail, wp_options in a tutorial post — so narrow the search to the tables or columns that actually need it rather than replacing every match.
Quick answers
Does changing the table prefix meaningfully improve security?
Only marginally. It's not WordPress's own primary hardening recommendation, and anyone with database access already has what the prefix would have hidden. Treat it as housekeeping, not a security control worth disrupting a live site over.
Can WP-CLI rename the prefix for me in one command?
No single built-in command does the whole job safely. wp search-replace handles the serialized-data cleanup step well, but renaming the tables and editing wp-config.php are separate, manual steps.
What happens if I miss the wp_capabilities meta key?
Every user account loses its role and capabilities from WordPress's point of view — which can look identical to a broken login even though the password itself is completely fine.
Is this safe to do on a live multisite network?
Meaningfully riskier — every subsite has its own numbered table set that needs the same treatment, and a missed table on any one subsite breaks just that site. Test the full procedure on a staging copy of the whole network first.
Primary reference: WP-CLI: wp search-replace.