1582
MySQLERRORNotableLoggingHIGH confidence

Bad statement for log table operation

Production Risk

Low — the statement is refused; log data is preserved.

What this means

An invalid or disallowed SQL statement was attempted against a log table.

Why it happens
  1. 1Attempting to INSERT, UPDATE, or DELETE rows directly in mysql.general_log or mysql.slow_log.
  2. 2Attempting to create an index or trigger on a log table.
How to reproduce
trigger — this will error
trigger — this will error
DELETE FROM mysql.general_log WHERE event_time < DATE_SUB(NOW(), INTERVAL 30 DAY);

expected output

ERROR 1582 (HY000): You can't use locks with log tables.

Fix

Disable logging, truncate, then re-enable

Disable logging, truncate, then re-enable
SET GLOBAL general_log = 'OFF';
TRUNCATE TABLE mysql.general_log;
SET GLOBAL general_log = 'ON';

Why this works

Log tables must be disabled before truncation; direct DML is not permitted while logging is active.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1582 ER_BAD_LOG_STATEMENT

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors