Error 1015 indicates that MySQL cannot obtain a required file lock, usually on a table’s .frm, .ibd, or system metadata file.
MySQL Error 1015: ER_CANT_LOCK occurs when the server cannot acquire an operating-system file lock on a table or index file. Check file permissions, open-file limits, and concurrent sessions, then retry or restart the affected operation to clear the lock.
Can't lock file (errno: %d - %s)
MySQL raises Error 1015 with the message "Can't lock file" when it fails to obtain an exclusive or shared lock on a table-related file. The lock request comes from DDL, INSERT, UPDATE, or an ALTER TABLE that needs metadata consistency.
Lock acquisition can fail because the file is already locked by another MySQL thread, an external process, or the operating system due to stale descriptors.
The error stops the current statement and rolls back any partial work to preserve data integrity.
Leaving file locks unresolved stalls application traffic, blocks automation tasks, and risks deadlocks that escalate into server freezes. Rapid identification and resolution restore normal throughput and prevent corrupted metadata.
High concurrency during heavy write workloads often triggers competing locks on .ibd files inside InnoDB tablespaces.
OS limits on open files or mandatory locking options also contribute.
Permission changes on the data directory or antivirus scans that hold handles can block MySQL from locking its own files, surfacing Error 1015.
First, locate the blocking session with SHOW PROCESSLIST or performance_schema metadata_lock_info.
Kill or wait for the session to finish, then retry the statement.
If no MySQL thread holds the lock, inspect the OS with lsof or fuser to find external processes. Stop the process, ensure proper permissions, and validate that the MySQL user owns the files.
During online ALTER TABLE, Error 1015 may appear if another thread starts a concurrent ALTER.
Serialize schema changes using pt-online-schema-change or Galaxy’s endorsed query workflows.
On Windows, aggressive antivirus locks .ibd files. Add the MySQL data directory to the exclusion list to eliminate interference.
Apply explicit metadata locking-timeout limits (e.g., lock_wait_timeout = 60) and monitor waits.
Automate schema migrations during low-traffic windows.
Use Galaxy’s versioned query library to schedule schema changes from a single governed pipeline, reducing accidental simultaneous DDL.
Error 1205 (Lock wait timeout) surfaces when a transaction waits too long rather than failing instantly. Increase innodb_lock_wait_timeout or optimize indexing.
Error 1025 (Error on rename) appears during ALTER TABLE RENAME if MySQL cannot lock both source and target tables. Resolve underlying file locks similarly to Error 1015.
.
Run lsof or fuser on Unix, or Process Explorer on Windows, targeting the exact .ibd/.frm file path.
Restarting frees internal locks but not external ones. Ensure third-party tools release file handles before restart.
Yes. Galaxy’s endorsed query workflow lets teams schedule schema changes in a single pipeline, avoiding overlapping ALTER TABLE commands.
Using O_DIRECT or ALL_O_DIRECT may change how the OS handles locks, but Error 1015 typically relates to metadata files, not flushed pages.