Common SQL Errors

MySQL Error 1556 ER_CANT_LOCK_LOG_TABLE: You Can't Use Locks With Log Tables - Fix and Prevention Guide

Galaxy Team
August 7, 2025

<p>Error 1556 occurs when a statement tries to lock the special log tables (general_log or slow_log), which MySQL forbids.</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 1556 ER_CANT_LOCK_LOG_TABLE?

<p>MySQL Error 1556: ER_CANT_LOCK_LOG_TABLE means the server rejected an explicit LOCK TABLES or similar command on general_log or slow_log. Remove or skip the lock operation, or switch logging to FILE, to resolve the issue.</p>

Error Highlights

Typical Error Message

You can't use locks with log tables.

Error Type

Locking Error

Language

MySQL

Symbol

ER_CANT_LOCK_LOG_TABLE

Error Code

1556

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1556 ER_CANT_LOCK_LOG_TABLE?

The error 'You can't use locks with log tables' occurs when a statement attempts to explicitly lock a log table with LOCK TABLES or performs an implicit lock through ALTER TABLE, CREATE INDEX, or certain DDL operations. MySQL treats general_log and slow_log as protected log tables and disallows explicit locking because that would interrupt the server's ability to write new log rows.

Maintenance scripts, backup utilities, or ad-hoc sessions that issue blanket LOCK TABLES across all tables will trigger the error when the command reaches one of the log tables. The server aborts the lock request, returning SQLSTATE HY000 and error code 1556.

What Causes This Error?

LOCK TABLES general_log WRITE or LOCK TABLES slow_log WRITE directly causes the error because MySQL blocks write locks on log tables. Wildcard statements such as LOCK TABLES * WRITE or automation loops that lock every table in the current schema also fail once they encounter a log table.

mysqldump with the --lock-tables option produces the same failure if the dump includes the mysql system database where log tables reside. Older ALTER TABLE commands on log tables can also invoke an implicit lock and generate error 1556.

How to Fix MySQL Error 1556 ER_CANT_LOCK_LOG_TABLE

Remove log tables from explicit LOCK TABLES lists. Optionally switch logging output to FILE during the operation: SET GLOBAL general_log = 'OFF'; SET GLOBAL log_output = 'FILE'; perform maintenance; SET GLOBAL log_output = 'TABLE'; SET GLOBAL general_log = 'ON'.

When using mysqldump, add --skip-lock-tables or --no-tablespaces, or restrict the dump to databases that do not include log tables. Application code should detect table names general_log and slow_log and bypass locking logic.

Common Scenarios and Solutions

Backup scripts that iterate through INFORMATION_SCHEMA.TABLES must filter out ENGINE='CSV' or TABLE_NAME IN ('general_log','slow_log'). Doing so allows the rest of the lock sequence to proceed.

Migration frameworks that default to LOCK TABLES * WRITE should switch to FLUSH TABLES WITH READ LOCK, which does not lock the individual log tables yet still offers a global read lock for snapshot creation.

Best Practices to Avoid This Error

Keep logging output to FILE when frequent global locks are required, especially on busy servers. Maintain separate maintenance users that lock only transactional tables explicitly listed, never using wildcards.

Monitor the MySQL error log for code 1556 and update scripts promptly. Document log table restrictions in developer guidelines to prevent future errors.

Related Errors and Solutions

Error 1557 ER_CANT_ROTATE_LOGFILE appears when MySQL cannot rotate log files; check file system permissions on log directories. Error 1558 ER_BAD_LOG_STATEMENT signals invalid log-related statements; verify syntax and parameter names. Unlike 1556, these errors relate to file handling and syntax rather than table locking.

Common Causes

Explicit LOCK TABLES on general_log

Running LOCK TABLES general_log WRITE fails because MySQL forbids write locks on log tables.

Wildcard LOCK TABLES * WRITE

Scripts that lock every table in a schema inevitably hit log tables and trigger error 1556.

mysqldump --lock-tables on mysql database

Dumping the mysql system database with --lock-tables attempts to lock log tables, producing the error.

Related Errors

MySQL Error 1557 ER_CANT_ROTATE_LOGFILE

Occurs when the server cannot rotate a log file. Check directory permissions.

MySQL Error 1558 ER_BAD_LOG_STATEMENT

Raised for malformed log-related SQL. Review SET GLOBAL or SHOW statements for typos.

MySQL Error 1223 ER_LOCK_WAIT_TIMEOUT

Indicates a lock wait timeout, unrelated to log tables but still about locking.

FAQs

Can I ever lock log tables safely?

No. MySQL intentionally prevents explicit locks on log tables to keep logging uninterrupted.

Does FLUSH TABLES WITH READ LOCK trigger error 1556?

No. That command applies a global read lock without touching individual log tables.

Will switching log_output to FILE avoid the error?

Yes. When log_output is FILE, log tables are not actively used, enabling scripts that lock all non-log tables.

How does Galaxy help here?

Galaxy highlights system tables like general_log in the schema viewer, warning users before they add them to LOCK TABLES statements, reducing the chance of error 1556.

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