Common SQL Errors

MySQL Error 1016: ER_CANT_OPEN_FILE – Causes, Fixes, and Prevention

Galaxy Team
August 5, 2025

MySQL cannot locate the necessary tablespace or .ibd file even though the .frm exists, preventing the table from opening.

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 1016?

MySQL Error 1016: ER_CANT_OPEN_FILE means InnoDB cannot find or access the table’s physical tablespace on disk, even though its .frm definition file is present. Check the table’s .ibd location, verify file permissions, and run ALTER TABLE ... DISCARD/IMPORT TABLESPACE or restore from backup to resolve the problem.

Error Highlights

Typical Error Message

Can't open file: '%s' (errno: %d - %s)

Error Type

Storage Engine Error

Language

MySQL

Symbol

ER_CANT_OPEN_FILE

Error Code

1016

SQL State

Explanation

Table of Contents

What is MySQL Error 1016: ER_CANT_OPEN_FILE?

What does the exact message mean?

MySQL throws "Can't open file: '%s' (errno: %d - %s)" when the InnoDB engine cannot locate or read the tablespace (.ibd) referenced by the table’s .frm metadata. The SQLSTATE is HY000, signaling a general storage engine failure.

Although the .frm file still exists in the database directory, the corresponding data file is missing, moved, corrupted, or locked by the operating system.

The server therefore blocks any query needing that table.

When does the error surface?

The error appears during SELECT, INSERT, UPDATE, or ALTER statements, and on server start-up if InnoDB scans the data dictionary and fails to open the table. It often follows filesystem operations or crashes.

Why is immediate action critical?

Leaving the table inaccessible halts application features that rely on it, risks cascading failures, and hints at deeper storage issues.

Rapid diagnosis protects data integrity and uptime.

What Causes This Error?

InnoDB cannot map the logical table to its physical .ibd file because the file is missing, renamed, has the wrong permissions, or resides on a detached volume.

Mismatched table IDs after a partial restore also trigger the error.

A crash during an ALTER TABLE that copied data out and back can leave the new .ibd orphaned, breaking the metadata link.

How to Fix MySQL Error 1016

First, validate that the .ibd file exists in the database directory. If it is missing, locate a recent backup and copy it back.

Second, ensure the file owner and permission bits allow mysqld to read and write.

If the .ibd exists but the internal table ID mismatches, use ALTER TABLE tbl DISCARD TABLESPACE; followed by ALTER TABLE tbl IMPORT TABLESPACE; after placing a valid .ibd copy in the directory. Always run ANALYZE TABLE after import.

Common Scenarios and Solutions

Scenario: you renamed the table’s folder at the OS level.

Solution: revert the folder name or update the datadir, then restart MySQL.

Scenario: the disk filled, causing corruption. Solution: free space, run mysqlcheck --repair or InnoDB recovery mode 1, then test.

Best Practices to Avoid This Error

Never manipulate .ibd or .frm files directly; use SQL commands. Keep regular logical and physical backups. Monitor disk health and permissions with automated checks.

Enable innodb_file_per_table and ensure backups capture both .frm and .ibd files.

Verify restore scripts on staging regularly.

Related Errors and Solutions

Error 1146 (ER_NO_SUCH_TABLE) occurs when both .frm and .ibd are missing. Error 1030 (ER_GET_ERRNO) indicates general filesystem errors. These share root causes and similar repair steps but differ in missing metadata scope.

Error 1812 (Tablespace is missing for table) specifically flags lost .ibd files in newer MySQL versions and can be resolved with the same DISCARD/IMPORT workflow.

.

Common Causes

Related Errors

FAQs

Does restarting MySQL fix error 1016?

A simple restart rarely resolves the missing file. It may even prevent startup if the table loads at boot.

Can I ignore the error if the table is unused?

You can drop the table to silence the error, but verify no code references it and back up data first.

How does Galaxy help prevent this error?

Galaxy surfaces schema changes, discourages manual filesystem edits, and tracks ALTER TABLE statements, reducing human error.

Is DISCARD/IMPORT safe on production?

Yes when using verified backups and running inside a transaction window. Always test on staging first.

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