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.
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
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
A plain find-and-replace can silently corrupt serialized data — here is how to do it without breaking the site.
How to create a MySQL database and userEvery application needs a database, a user, and that user attached to the database — here is the order to do it in.
What is wp-config.php and what is in it?The one file that connects WordPress to its database and controls a handful of settings nothing else can reach.
How to grant a user access to a databaseA database user with no privileges cannot do anything, and one with too many is a risk you do not need to take.