<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>
<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>
Temporary
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.
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.
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.
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.
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.
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.
An interrupted ALTER TABLE, CREATE INDEX, or OPTIMIZE TABLE left #sql-*.ibd or .frm files in the database directory.
A session tried to create a temporary table with a name already in use within that session or another concurrent one.
Someone copied production data files into the datadir for debugging, unknowingly duplicating a #sql-prefixed file.
On replicas, an older temporary object still existed when the same DDL arrived from the source.
Raised when creating a permanent table with a duplicate name. Resolve by dropping or renaming the existing table.
Indicates MySQL could not write to the temporary directory, often due to full disk or permission issues.
Occurs during table rename when the target name already exists or filesystem errors block renaming.
Usually no. The error prevents MySQL from overwriting existing data. Orphaned files are copies, not the live table.
Yes if the conflict is only in the data dictionary. DROP the temporary table and retry. File deletions, however, need a safe shutdown.
MySQL uses the #sql prefix for internal temporary objects created during DDL operations to keep them separate from user tables.
Galaxy tracks DDL history, flags failed operations, and lets teams see leftover #sql objects quickly, reducing orphaned files.