mysqldude
Error codes › 1050

MySQL & MariaDB error 1050: Table already exists

Error messageTable '…' already exists
Example from our test runs: Table 't' already exists (5.6.51)

CREATE TABLE or RENAME TABLE targets a name that is already taken. Typical of migrations run twice. Use IF NOT EXISTS or check what is there first.

MySQLMariaDB
SymbolER_TABLE_EXISTS_ERRORER_TABLE_EXISTS_ERROR
SQLSTATE42S0142S01
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

The database already has a table (or view) with that name, so CREATE TABLE, CREATE VIEW or RENAME TABLE … TO can’t use it.

Why it happens

  • A migration or install script runs a second time, or a previous run stopped half way after creating some tables.
  • RENAME TABLE new TO old in a swap-table deployment when the old table wasn’t renamed out of the way first.
  • A view and a table share one namespace, so a view with the same name also blocks the CREATE TABLE.
  • Rarely, after files were copied by hand or a crash, InnoDB still has a tablespace for the name. That case usually shows as 1813 “Tablespace exists” rather than 1050.

How to fix it

  • CREATE TABLE IF NOT EXISTS … makes the statement a no-op that only raises a note. It won’t change an existing table whose definition differs, so check that separately.
  • Look before you create: SHOW TABLES LIKE 'orders'; or query information_schema.TABLES.
  • For table swaps, do it atomically in one statement: RENAME TABLE orders TO orders_old, orders_new TO orders;.
  • If the table is really leftover from a failed run and holds nothing you need, DROP TABLE it and rerun.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE t (a INT);
  2. Run:

    CREATE TABLE t (a INT);

You get: Table 't' already exists(11.8.9)

Verified fixes

  1. CREATE TABLE IF NOT EXISTS (turns the error into a note)

    CREATE TABLE IF NOT EXISTS t (a INT);
    SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 't';

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Run the CREATE TABLE of a migration a second time
repro
✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050
RENAME TABLE onto a name that is already taken
version check
✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050✓ 1050
CREATE TABLE IF NOT EXISTS (turns the error into a note)
fix
✓✓✓✓✓✓✓✓✓
Run the CREATE TABLE of a migration a second time repro
MySQL 5.6✓ 10505.7✓ 10508.0✓ 10508.4✓ 10509✓ 1050
MariaDB 10.6✓ 105010.11✓ 105011.4✓ 105011.8✓ 1050
RENAME TABLE onto a name that is already taken version check
MySQL 5.6✓ 10505.7✓ 10508.0✓ 10508.4✓ 10509✓ 1050
MariaDB 10.6✓ 105010.11✓ 105011.4✓ 105011.8✓ 1050
CREATE TABLE IF NOT EXISTS (turns the error into a note) fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1146 ER_NO_SUCH_TABLEexplained
  • 1060 ER_DUP_FIELDNAMEexplained
  • 1813 ER_TABLESPACE_EXISTS