If you’ve landed on this blog post, there’s a good chance you’re well into your journey of securing your WordPress website. Changing your database prefix is a simple but effective step against automated attacks and sneaky SQL injection attempts. I created this little guide to walk you through exactly what a database prefix is, why you should change it, and all the different ways you can get the job done safely.
What’s a WordPress Database Prefix, Anyway?
Think of the WordPress database prefix as a little tag on every table name in your database. By default, WordPress uses “wp_”, so you end up with table names like wp_posts, wp_users, and wp_options.

It serves a few key purposes:
- It keeps things tidy. It helps organise your tables and keeps them from bumping into other tables, especially if you have multiple WordPress installations sharing the same database.
- It helps you spot your tables easily. When you’re looking at your database, you can quickly tell which tables belong to WordPress.
- It adds a bit of security. Changing this default prefix is a simple way to add a layer of “security through obscurity.”
Why Bother Changing It?
Enhanced Security
The biggest reason to change your prefix is to boost your site’s security. The default “wp_” prefix is famous, which makes your site a sitting duck for:
- SQL injection attacks: Attackers know the default prefix, making it easy to create targeted queries to steal or mess with your data.
- Automated attacks: Malicious bots often scan for the default WordPress table names to launch mass attacks.
- Brute-force attempts: When hackers can easily spot a WordPress site, it’s easier for them to target known vulnerabilities.
By changing the prefix to something unique and unpredictable, you make it much harder for attackers to target your database.
Avoiding Table Collisions
If you’re running multiple WordPress sites or other applications from a single database, using a unique prefix for each installation is crucial. It keeps all their tables separate and well-organised.
Security by Obscurity
While it’s not a complete fix on its own, changing the database prefix is a good example of “security by obscurity.” The idea is that if an attacker has to work harder to find what they’re looking for, they might just give up and move on to an easier target.
When Should You Change the Prefix?
New Installations
The best time to do this is when you first set up your site. During the famous 5-minute WordPress installation, you’ll be prompted to enter a prefix. Just replace the default “wp_” with your own custom prefix. It’s that easy.
Existing Sites
If your site is already up and running, it’s a bit more complicated, but still totally doable. The process requires extra care because:
- Existing data already references the old prefix.
- Some of your plugins might have created their own tables with that old prefix.
- User permissions and other settings are tied to the old prefix.
Before You Start: Preparation is Key
Back Everything Up
Seriously, don’t skip this step. You must have a complete backup before you make any changes.
- Database backup: Export your entire database.
- File backup: Save all your WordPress files, especially wp-config.php.
- Test your backup: Make sure you can restore your site from this backup if something goes wrong.
Deactivate Plugins and Switch Themes (Optional)
Before you begin, you should:
- Deactivate all your plugins. Some plugins have their own database tables, and you don’t want them getting in the way.
- Switch to a default WordPress theme, like Twenty Twenty-Four.
- Clear your cache, especially if you’re using a caching plugin.
Check File Permissions
You’ll be editing your wp-config.php file, so make sure it’s writable.
Method 1: The Manual Approach
This method gives you full control.
Step 1: Edit wp-config.php
Open up your wp-config.php file in your WordPress root directory. You’ll see a line that looks like this:
$table_prefix = 'wp_';
Change it to your new prefix, something like this:
$table_prefix = 'wp_secure123_';

Important: Don’t save the file just yet! We’ll come back to this after we’ve changed the database.
Step 2: Access phpMyAdmin
Log in to your hosting account and find phpMyAdmin. It’s usually in cPanel or your hosting provider’s custom control panel.
Step 3: Rename Your Database Tables
Inside phpMyAdmin:
- Select your WordPress database from the left sidebar.
- Go to the Structure tab to see a list of all your tables.
- Select all of the default WordPress tables (there are usually 12).
- Choose Replace table prefix from the “With selected” dropdown menu.
- In the “From” field, enter your old prefix (wp_).
- In the “To” field, enter your new prefix (wp_secure123_).
- Click Continue.
Step 4: Update Internal References
WordPress stores a few internal references that also need to be updated. You’ll need to run a couple of SQL queries.
Update the options table:
UPDATE wp_secure123_options
SET option_name = REPLACE(option_name, 'wp_', 'wp_secure123_')
WHERE option_name LIKE '%wp_%';
Update the usermeta table:
UPDATE wp_secure123_usermeta
SET meta_key = REPLACE(meta_key, 'wp_', 'wp_secure123_')
WHERE meta_key LIKE '%wp_%';
Step 5: Save wp-config.php
Now you can finally save your wp-config.php file. The timing here is critical; you need to make sure the database and the config file are in sync.
Method 2: Use a Plugin
If you’re not comfortable with the manual method, a plugin can do all the heavy lifting for you.
Brozzme DB Prefix & Tools Addons
This plugin is a quick and easy solution.
- Install and activate the plugin.
- Go to Tools > DB Prefix.
- Enter your new prefix (or let the plugin generate one for you).
- Click the change button.
Keep in mind: Your wp-config.php file must be writable, and your database needs to have ALTER privileges. And, as always, create a backup first!
Solid security (formerly iThemes Security)
This popular security plugin also has this functionality built in.
- Install and activate Solid Security.
- Go to the Security dashboard in your wp-admin panel.
- Navigate to the Tools tab and find the Database Security section.
- Click Run to have the plugin automatically generate and apply a new prefix.
This plugin will choose a prefix for you, rather than letting you create a custom one.
Method 3: Using SQL Queries
For advanced users comfortable with SQL, you can use automated queries:
SET @database = "your_database_name";
SET @old_prefix = "wp_";
SET @new_prefix = "wp_secure123_";
SELECT concat(
"RENAME TABLE ", TABLE_NAME,
" TO ", replace(TABLE_NAME, @old_prefix, @new_prefix), ';'
) AS "SQL"
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @database;
This generates RENAME TABLE statements that you can then execute.
Best Practices for Your New Prefix
Best Practices for Choosing a New Prefix
Prefix Requirements
WordPress requires that database prefixes:
- Contain only numbers, letters, and underscores
- End with an underscore (recommended but not required)
- Be unique and difficult to guess
Strong Prefix Examples
Instead of simple prefixes like “blog_” or “site_”, use more complex combinations:
wp_a7k9m3_
wp_secure2024_
wp_mysite847_
Security Considerations
- Avoid predictable patterns like your domain name or common words
- Use a mix of letters and numbers
- Keep it reasonably short but sufficiently complex
- Consider it like a password – the more random, the better
Common Troubleshooting Issues
Site Shows Installation Screen
If your site displays the WordPress installation screen after changing the prefix:
- Check wp-config.php: Ensure the table prefix matches your database tables exactly
- Verify database changes: Confirm all tables were renamed successfully
- Check plugin tables: Some plugins create additional tables that may need renaming
Plugin Compatibility Issues
Some plugins may have issues with non-standard prefixes:
- Reactivate plugins one by one to identify problematic ones
- Check plugin documentation for prefix-related requirements
- Contact plugin developers for compatibility information
Missing User Permissions
If you can’t access the admin area:
- Check usermeta table updates: Ensure user capabilities were updated correctly
- Verify options table: Confirm user roles were updated with the new prefix
- Restore from backup if issues persist
Database Tables That Need Attention
Default WordPress Tables
WordPress installations typically include these 12 default tables:
- wp_commentmeta
- wp_comments
- wp_links
- wp_options
- wp_postmeta
- wp_posts
- wp_terms
- wp_termmeta
- wp_term_relationships
- wp_term_taxonomy
- wp_usermeta
- wp_users
Plugin-Created Tables
Many plugins create additional database tables. Common examples include:
- SEO plugins: Often create tables for redirect management
- Security plugins: May store login attempt logs
- E-commerce plugins: Create product and order tables
- Form plugins: Store form submissions and configurations
Critical Internal References
Pay special attention to these internal WordPress references:
- User capabilities: Stored in wp_usermeta as
wp_capabilities
- User roles: Stored in wp_options as
wp_user_roles
- User levels: Stored in wp_usermeta as
wp_user_level
Security Limitations
Changing your database prefix is a great step, but it’s not a silver bullet. It won’t protect you from every attack. You should always combine it with other security measures, like:
- Keeping your site, themes, and plugins updated.
- Use strong passwords for all your accounts.
- Installing a comprehensive security plugin.
- Regularly backing up your site.
- Using an SSL certificate (HTTPS).
By combining these practices, you’ll create a robust defence system that makes your WordPress site significantly more secure.
Would you like to know more about any of the methods, or perhaps learn about other ways to improve your site’s security?