FAQ Databases & MySQL

What is a database table prefix?

A short string in front of every table name, mainly so more than one application can share the same database.

Updated 4 min read Beginner

A table prefix is a short string added to the front of every table name in a database — wp_posts, wp_options, wp_users and so on for a default WordPress install using the standard wp_ prefix. It exists so that a single database can safely hold the tables for more than one application without their table names colliding.

Why it matters

A database is just a flat collection of tables — there is no built-in concept of "this table belongs to this application". If two separate WordPress installs both tried to create a table simply named posts in the same database, the second install would either fail or, worse, overwrite the first one's data. Giving each install its own prefix — wp_ for one, wp2_ or something more distinctive for another — means both sets of tables can sit in the same database without ever touching each other.

Most WordPress installs still get their own dedicated database rather than sharing one, in which case the prefix is not doing much practical work day to day. But it costs nothing to have, and it is what makes sharing a database an option at all rather than something that simply cannot be done.

Where to find it

For WordPress, the prefix is set in wp-config.php:

$table_prefix = 'wp_';

Whatever value is there has to match the actual tables in the database exactly. If you ever see WordPress reporting that it cannot find its tables despite the database clearly containing them, a mismatched prefix in this line — often introduced when copying a site between hosts — is one of the more common causes.

Does changing it improve security?

Changing the prefix away from the well-known default is sometimes suggested as a security measure, on the reasoning that an attacker's script targeting wp_users by name will not find anything to attack. It is a genuinely minor obstacle at best — anyone with real database access, whether legitimate or through a compromised credential, can see the actual table names immediately, and it does nothing to close the kind of vulnerability that grants that access in the first place. It is not a meaningful substitute for keeping WordPress, themes and plugins updated, using a strong database password, and following the practices in granting database privileges properly.

Changing an existing prefix safely

This is not a simple rename

Changing the prefix on a live WordPress site means renaming every table and also updating references to the old prefix stored as data inside some of those tables — certain rows in wp_options and wp_usermeta refer to table and column names by their prefixed form. Back up the database fully before attempting this, and use a tool built for the job — WP-CLI's search-replace command, or a dedicated migration plugin — rather than renaming tables by hand and hoping nothing references the old names.

Our guide to searching and replacing inside a database covers the serialized-data problem that makes a naive find-and-replace risky here, which is the same underlying issue.

Related reading