// MySQL error reference

MySQL error 1050: Table already exists

CREATE TABLE (or RENAME TABLE) uses a name that's already taken in that database by a table or view.

Error number
1050
Name
ER_TABLE_EXISTS_ERROR
SQLSTATE
42S01
Category
Databases, tables and columns
Error message
Table '%s' already exists

What it means

A database can hold only one table or view with a given name. Creating or renaming to a name that exists fails with 1050. Re-running a migration or setup script is the usual trigger.

Common causes

  • Running the same CREATE TABLE script twice.
  • A migration that already ran partially.
  • A view with the same name as the table you're creating.

How to fix it

  1. Make the script idempotent.

    CREATE TABLE IF NOT EXISTS audit_log (
        id BIGINT AUTO_INCREMENT PRIMARY KEY,
        msg TEXT
    );
  2. If you meant to replace the table, drop it first (this deletes its data).

    DROP TABLE IF EXISTS audit_log;

Related errors

More databases, tables and columns errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.