Common SQL Errors

MySQL Error 1086: ER_FILE_EXISTS_ERROR - How to Fix and Prevent

Galaxy Team
August 5, 2025

MySQL raises ER_FILE_EXISTS_ERROR when a CREATE statement targets a file or object name that already exists in the database directory.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL Error 1086 (ER_FILE_EXISTS_ERROR)?

MySQL Error 1086: ER_FILE_EXISTS_ERROR means the server found an existing file or object with the same name you are trying to create. Remove or rename the conflicting file, or add IF NOT EXISTS to your CREATE statement to resolve the issue quickly.

Error Highlights

Typical Error Message

File '%s' already exists

Error Type

Object Creation Error

Language

MySQL

Symbol

ER_FILE_EXISTS_ERROR

Error Code

1086

SQL State

Explanation

Table of Contents

What is MySQL error 1086 (ER_FILE_EXISTS_ERROR)?

MySQL returns the message File '%s' already exists with error code 1086 when the server attempts to create a table, view, trigger, stored routine, or external file whose name or path is already present in the data directory.

The statement is aborted to protect existing data.

Any dependent logic fails until the conflicting object is removed, renamed, or the statement is changed to handle duplicates safely.

What Causes This Error?

Duplicate object names are the primary trigger.

If a table, view, or temporary file with the same name exists, MySQL refuses to overwrite it.

Leftover .frm, .ibd, or .MYD files from an unclean shutdown can also cause the server to think the object still exists even after a DROP statement.

File system quirks such as case sensitivity differences on Windows vs Linux can make names appear unique in SQL but identical on disk.

How to Fix MySQL Error 1086: ER_FILE_EXISTS_ERROR

First, confirm the conflicting object with SHOW TABLES, SHOW FULL TABLES, or an INFORMATION_SCHEMA query.

If the object is valid, choose a new name.

If the file is orphaned, DROP the object in SQL or delete residual files from the data directory after a full backup. Adding IF NOT EXISTS to CREATE statements prevents the error automatically.

Common Scenarios and Solutions

During restores, mysqldump files often contain CREATE TABLE statements without IF NOT EXISTS, triggering the error.

Edit the dump or add the --skip-create-options flag.

When running CREATE TABLE LIKE or CREATE VIEW, developers sometimes reuse the same destination name. Renaming the new object or using a staging schema fixes the conflict.

LOAD DATA INFILE INTO TABLE can raise error 1086 if the target table was accidentally created earlier in the session.

Ensure the table is dropped before rerunning the load.

Best Practices to Avoid This Error

Adopt naming conventions that embed timestamps or environment prefixes to guarantee uniqueness across dev, staging, and prod.

Include IF NOT EXISTS or OR REPLACE clauses (for views, triggers, routines) in automated scripts.

Galaxy’s SQL editor autocompletes these clauses, lowering typo risk.

Schedule periodic checks that scan data directories for orphaned files and reconcile them with INFORMATION_SCHEMA metadata.

Related Errors and Solutions

Error 1050 ER_TABLE_EXISTS_ERROR occurs when a table name clash happens at the metadata level rather than the file system. Dropping or renaming the table resolves it.

Error 1007 ER_DB_CREATE_EXISTS arises when you attempt to CREATE DATABASE with an existing name.

Adding IF NOT EXISTS bypasses the problem.

Error 1022 ER_DUP_KEYNAME signals a duplicate key when adding an index. Renaming the index or key fixes it.

.

Common Causes

Related Errors

FAQs

Why do I still get error 1086 after dropping the table?

An orphaned .frm or .ibd file may remain on disk. Stop MySQL, back up, and delete the stray files manually.

Is IF NOT EXISTS safe in production?

Yes. It prevents accidental overwrites while allowing idempotent deployment scripts.

Can I ignore the error during restores?

Add --force to mysql client or edit the dump with IF NOT EXISTS, but verify that skipping the object will not break dependencies.

How does Galaxy help avoid this error?

Galaxy’s editor warns about duplicate object names and autocompletes IF NOT EXISTS, reducing the chance of error 1086 in team workflows.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo