1221
MySQLERRORNotableLockingHIGH confidence
Cannot combine WRITE locks for system and user tables
Production Risk
Low — operation fails safely; restructure locking strategy.
What this means
ER_WRONG_LOCK_OF_SYSTEM_TABLE (1221, SQLSTATE HY000) is raised when a LOCK TABLES statement tries to acquire WRITE locks on both system tables (e.g., mysql.user) and regular user tables simultaneously.
Why it happens
- 1Including both mysql.* system tables and user-defined tables in a single LOCK TABLES ... WRITE statement
How to reproduce
trigger — this will error
trigger — this will error
LOCK TABLES mysql.user WRITE, my_app.orders WRITE; -- ERROR 1221
expected output
ERROR 1221 (HY000): You can't combine write-locking of system and user tables
Fix
Lock system tables and user tables separately
Lock system tables and user tables separately
-- Lock only user tables LOCK TABLES my_app.orders WRITE; -- Do work, then unlock UNLOCK TABLES;
Why this works
System tables require separate locking contexts from user tables.
Sources
Official documentation ↗
MySQL 8.0 — 1221 ER_WRONG_LOCK_OF_SYSTEM_TABLE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev