Common SQL Errors

MySQL Error 1635: ER_TEMPORARY_NAME - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL raises ER_TEMPORARY_NAME (code 1635) when it tries to create an internal or user-defined temporary table whose autogenerated #sql file name already exists.</p>

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 code 1635?

<p>MySQL Error 1635: ER_TEMPORARY_NAME occurs when the server cannot create a temporary table because a file or table with the autogenerated #sql name already exists. Remove or drop the conflicting file/table or clean up the datadir, then rerun the statement.</p>

Error Highlights

Typical Error Message

Temporary

Error Type

Runtime Error

Language

MySQL

Symbol

ER_TEMPORARY_NAME

Error Code

1635

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1635: ER_TEMPORARY_NAME?

MySQL throws error 1635 with the condition name ER_TEMPORARY_NAME and SQLSTATE HY000 when it fails to create a temporary object whose autogenerated filename starts with #sql. The server generates these names during ALTER TABLE, CREATE INDEX, OPTIMIZE TABLE, or explicit CREATE TEMPORARY TABLE operations.

The error signals that the intended #sql-prefixed file or dictionary entry already exists either on disk or in the data dictionary. MySQL aborts the statement to avoid overwriting data.

What Causes This Error?

Filename collisions most often happen after an earlier DDL crashed, leaving orphaned #sql files. When MySQL retries a similar operation, it re-creates the same name and detects the conflict.

Other triggers include duplicate CREATE TEMPORARY TABLE names inside the same session, manual file copies into the datadir, or insufficient cleanup in multi-server replication setups.

How to Fix MySQL Error 1635: ER_TEMPORARY_NAME

First, identify the conflicting object. Check the server error log for the full path of the #sql file. If a leftover file exists, move it out of the datadir or delete it after a verified backup.

If the conflict is a user-defined temporary table, DROP TEMPORARY TABLE IF EXISTS table_name; then rerun the original command. For internal leftovers, use FLUSH TABLES, followed by a server restart when safe.

Common Scenarios and Solutions

During ALTER TABLE, MySQL builds a shadow copy named #sql-*.ibd. A crash leaves it behind, causing future ALTER attempts to fail. Removing the orphaned .ibd and .frm pair restores normal operation.

Developers creating the same TEMPORARY TABLE in multiple connections may hit the error. Use IF NOT EXISTS or unique suffixes to avoid duplicates.

Best Practices to Avoid This Error

Always allow DDL statements to finish and enable the innodb_fast_shutdown=0 setting before planned shutdowns so MySQL cleans up temporary files.

Monitor the datadir for stray #sql files with a scheduled script. Automate alerts in Galaxy collections so teammates see and resolve collisions quickly.

Related Errors and Solutions

ER_TABLE_EXISTS_ERROR (1050) appears when you create a permanent table that already exists. ER_TEMP_FILE_WRITE_FAILURE (1296) surfaces when the tmpdir is full. The troubleshooting approach is similar: locate the conflicting object or storage problem, remove it, then retry.

Common Causes

Crash-leftovers

An interrupted ALTER TABLE, CREATE INDEX, or OPTIMIZE TABLE left #sql-*.ibd or .frm files in the database directory.

Duplicate TEMPORARY TABLE names

A session tried to create a temporary table with a name already in use within that session or another concurrent one.

Manual file copies

Someone copied production data files into the datadir for debugging, unknowingly duplicating a #sql-prefixed file.

Replication delay

On replicas, an older temporary object still existed when the same DDL arrived from the source.

Related Errors

MySQL Error 1050: ER_TABLE_EXISTS_ERROR

Raised when creating a permanent table with a duplicate name. Resolve by dropping or renaming the existing table.

MySQL Error 1296: ER_TEMP_FILE_WRITE_FAILURE

Indicates MySQL could not write to the temporary directory, often due to full disk or permission issues.

MySQL Error 1025: ERROR_ON_RENAME

Occurs during table rename when the target name already exists or filesystem errors block renaming.

FAQs

Does this error damage my data?

Usually no. The error prevents MySQL from overwriting existing data. Orphaned files are copies, not the live table.

Can I fix ER_TEMPORARY_NAME without restarting MySQL?

Yes if the conflict is only in the data dictionary. DROP the temporary table and retry. File deletions, however, need a safe shutdown.

Why does the file name start with #sql?

MySQL uses the #sql prefix for internal temporary objects created during DDL operations to keep them separate from user tables.

How does Galaxy help?

Galaxy tracks DDL history, flags failed operations, and lets teams see leftover #sql objects quickly, reducing orphaned files.

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