Common SQL Errors

MySQL Error 1428: ER_WRONG_LOCK_OF_SYSTEM_TABLE - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>Raised when a WRITE lock is requested on a system table together with other tables or lock modes in the same LOCK TABLES statement.</p>

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 1428: ER_WRONG_LOCK_OF_SYSTEM_TABLE?

<p>MySQL Error 1428: ER_WRONG_LOCK_OF_SYSTEM_TABLE occurs when a WRITE lock is placed on a system table while other tables or lock types are included in the same LOCK TABLES statement. Issue separate LOCK TABLES calls or avoid WRITE locks on system tables to resolve the error.</p>

Error Highlights

Typical Error Message

You can't combine write-locking of system tables with

Error Type

Locking Error

Language

MySQL

Symbol

ER_WRONG_LOCK_OF_SYSTEM_TABLE

Error Code

1428

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1428: ER_WRONG_LOCK_OF_SYSTEM_TABLE?

MySQL throws Error 1428 with the message "You can't combine write-locking of system tables with other tables or lock types" when the LOCK TABLES statement includes a system table with a WRITE lock alongside any other table or lock mode. System tables include mysql.*, sys.*, performance_schema.*, and information_schema.*.

The server blocks this combination to protect critical metadata from deadlocks and corruption. Fixing it quickly is vital because the statement fails and any subsequent transactional logic depending on the lock sequence will also fail.

What Causes This Error?

The error arises whenever a WRITE lock is requested on a system table in the same statement that also locks non-system tables or requests a different lock mode, such as READ. MySQL enforces single-table WRITE locks on its internal schemas to ensure metadata consistency.

It can also be triggered indirectly by stored procedures, backup scripts, or third-party tools that attempt broad WRITE locks for snapshot consistency.

How to Fix MySQL Error 1428

Issue separate LOCK TABLES statements: first lock the required system table alone with WRITE, release it, then lock other tables as needed. Alternatively, switch to READ locks on system tables if writes are not required. In most cases, redesigning code to avoid modifying system tables is the safest fix.

When the goal is a consistent backup, use FLUSH TABLES WITH READ LOCK or the --single-transaction option of mysqldump instead of manual WRITE locks.

Common Scenarios and Solutions

Backup scripts: Replace multiple WRITE locks with FLUSH TABLES WITH READ LOCK to take snapshots without halting DML activity.

Metadata migrations: Use dedicated maintenance windows and lock only the target system table, or rely on MySQL DDL statements that handle locking internally.

Best Practices to Avoid This Error

Avoid direct writes to mysql.* and sys.* tables. Use GRANT, REVOKE, and ALTER USER commands instead of manual updates. If you must lock, never combine a system table WRITE lock with other locks in the same statement.

Automate checks in CI to scan code for LOCK TABLES statements referencing system tables. Monitor error logs to catch lock failures early.

Galaxy Integration

Galaxy's static analysis flags LOCK TABLES statements that target system tables with WRITE mode. The editor highlights the risky pattern and suggests splitting the locks. Collaborative review workflows help teams approve safe locking strategies before code reaches production.

Related Errors and Solutions

Error 1100 - ER_TABLE_NOT_LOCKED: occurs when a session tries to access a table it has not locked. Resolve by adding the correct lock before access.

Error 1205 - Lock wait timeout exceeded: appears when a transaction waits too long for a lock. Tune innodb_lock_wait_timeout or redesign the transaction order.

Error 1550 - ER_LOCK_TABLE_FULL: raised when the lock table memory is exhausted. Free unused locks or increase the lock table size.

Common Causes

Mixing WRITE and READ locks

Requesting a WRITE lock on mysql.user while also requesting a READ lock on another table in the same LOCK TABLES call.

Locking system and application tables together

Including a system table such as performance_schema.threads with a WRITE lock and an application table like app.orders.

Backup utilities using broad LOCK TABLES

Legacy scripts that attempt to lock every table with WRITE to create a consistent backup snapshot.

Manual privilege edits

Developers updating mysql.db directly and locking it with WRITE alongside other objects for convenience.

Related Errors

MySQL Error 1100 - ER_TABLE_NOT_LOCKED

Raised when a session accesses a table without the required lock. Ensure the table is locked before access.

MySQL Error 1205 - Lock Wait Timeout Exceeded

Occurs when a transaction waits too long for a lock. Reduce contention or increase the timeout.

MySQL Error 1550 - ER_LOCK_TABLE_FULL

Indicates the InnoDB lock table is full. Free locks or enlarge innodb_buffer_pool_size.

FAQs

Can I ever write-lock system tables safely?

Yes, but only lock the single system table with WRITE in its own LOCK TABLES statement and keep the transaction short.

Which schemas are considered system tables?

mysql, sys, performance_schema, and information_schema are regarded as system schemas for locking rules.

Does mysqldump trigger this error?

Not when run with --single-transaction. It uses transactional snapshots instead of WRITE locks on system tables.

How does Galaxy help prevent lock errors?

Galaxy analyzes SQL in real time, flags risky LOCK TABLES patterns, and recommends safe alternatives, reducing production errors.

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