ERROR 1150 occurs when a DELAYED insert thread cannot acquire the lock it needs to write to a table, often due to conflicting LOCK TABLES or FLUSH statements. This error is rare in modern MySQL (5.7+) since INSERT DELAYED has been deprecated and removed; if you encounter it, switch to regular INSERT statements or batch inserts.
This error is associated with MySQL's deprecated INSERT DELAYED feature, which was designed to defer insert operations asynchronously. When a delayed insert thread attempts to acquire a table lock to complete the pending insert, it fails because another connection holds an incompatible lock (such as a READ lock from LOCK TABLES or FLUSH TABLES). The delayed handler thread terminates without writing the queued data, resulting in potential data loss. MySQL 5.6 deprecated INSERT DELAYED, MySQL 5.7 began ignoring the keyword with a warning, and MySQL 8.0+ removed support entirely. Modern MySQL engines like InnoDB never supported DELAYED inserts at all.
Check which MySQL version you're running:
SELECT VERSION();Search your application code and queries for any use of INSERT DELAYED:
# In application code
grep -r "INSERT DELAYED" .
grep -r "insert delayed" . --ignore-caseIf you're on MySQL 5.7+, INSERT DELAYED is no longer functional. Proceed to the next step to replace it with regular INSERT statements.
Convert all INSERT DELAYED statements to standard INSERT statements. This is the primary fix:
Before (deprecated):
INSERT DELAYED INTO logs (user_id, action, timestamp)
VALUES (123, 'login', NOW());After (correct):
INSERT INTO logs (user_id, action, timestamp)
VALUES (123, 'login', NOW());For InnoDB tables (the default in MySQL 5.7+), regular INSERT is efficient and supports row-level locking, avoiding the lock contention that plagued INSERT DELAYED.
If you were using INSERT DELAYED for throughput improvement, replace it with batch inserts (multiple VALUES in one statement):
Before:
INSERT DELAYED INTO events (user_id, event_type) VALUES (1, 'click');
INSERT DELAYED INTO events (user_id, event_type) VALUES (2, 'scroll');
INSERT DELAYED INTO events (user_id, event_type) VALUES (3, 'close');After (batch insert):
INSERT INTO events (user_id, event_type)
VALUES
(1, 'click'),
(2, 'scroll'),
(3, 'close');Batch inserts are 83% faster than individual inserts in benchmarks and avoid the deadlock issues of INSERT DELAYED.
If your workload requires fire-and-forget inserts, implement async queueing at the application level instead of relying on the database:
Option 1: Message Queue (RabbitMQ, Redis Streams, AWS SQS)
// Pseudo-code
await messageQueue.enqueue({
table: 'logs',
data: { user_id: 123, action: 'login' }
});
// Worker process consumes and batches insertsOption 2: Staging Table with Batch Processing
-- Insert into temporary staging table (fast, no locks)
INSERT INTO logs_staging (user_id, action) VALUES (123, 'login');
-- Periodically batch merge into main table
INSERT INTO logs SELECT * FROM logs_staging LIMIT 1000;
DELETE FROM logs_staging WHERE id IN (SELECT id FROM logs LIMIT 1000);This gives you the performance benefits of async inserts without the reliability issues of INSERT DELAYED.
Test your updated insert statements:
-- Test regular insert
INSERT INTO your_table (col1, col2) VALUES ('value1', 'value2');
SELECT * FROM your_table WHERE col1 = 'value1'; -- Should return 1 row
-- Test batch insert
INSERT INTO your_table (col1, col2)
VALUES ('v1', 'v2'), ('v3', 'v4'), ('v5', 'v6');
SELECT COUNT(*) FROM your_table WHERE col1 IN ('v1', 'v3', 'v5'); -- Should return 3Confirm that ERROR 1150 no longer appears and all rows are inserted successfully.
INSERT DELAYED was removed from MySQL due to its inherent design flaws: the delayed handler thread uses mutexes in an order incompatible with the rest of the server, leading to numerous deadlocks and data loss scenarios. The combination of table locks (LOCK TABLES, FLUSH TABLES), DDL operations (ALTER TABLE), and DELAYED insert threads created unpredictable interactions that even affected replication and multi-table operations.
For modern applications requiring true asynchronous writes, do not rely on database features. Instead, use external message queues (RabbitMQ, Redis, Kafka) or implement staging tables with periodic bulk inserts. These approaches are more reliable, scale better across multiple servers, and avoid the synchronization issues that plagued INSERT DELAYED.
If you're upgrading from MySQL 5.5 or earlier, grep your codebase thoroughly for INSERT DELAYED. MySQL 5.7+ silently converts DELAYED inserts to regular inserts with a warning, which may mask migration issues.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions