How to Fix MySQL Error #1557: Corrupt Event Scheduler System Tables (mysqldump –events Issue)


3 views

When running mysqldump with the --events flag, you encounter:

mysqldump: Couldn't execute 'show events': Cannot proceed because system tables
     used by Event Scheduler were found damaged at server start (1577)

The error specifically points to corruption in MySQL's Event Scheduler system tables, typically the mysql.events table. The database otherwise functions normally, making this a silent but potentially serious issue.

First, verify the problem by checking the events table directly:

SELECT * FROM mysql.events;

If this returns error 1577, you've confirmed the corruption. For MyISAM storage engine (common for system tables in older MySQL versions):

mysqlcheck --check mysql events
# Or for deeper verification:
myisamchk /var/lib/mysql/mysql/events.MYI

For MySQL 5.1+ installations (which your v14.14 indicates), follow these steps:

# 1. Stop MySQL service
sudo service mysql stop

# 2. Repair the table (MyISAM)
myisamchk -r -q /var/lib/mysql/mysql/events.MYI
# If that fails:
myisamchk -r -o /var/lib/mysql/mysql/events.MYI
# As last resort:
myisamchk --safe-recover /var/lib/mysql/mysql/events.MYI

# 3. Verify repair
myisamchk -e /var/lib/mysql/mysql/events.MYI

# 4. Restart MySQL
sudo service mysql start

If repair fails, rebuild from scratch:

# 1. Dump event definitions (if possible)
mysqldump --no-create-info --events mysql > events_backup.sql

# 2. Drop corrupt table
mysql -e "DROP TABLE mysql.events;"

# 3. Recreate from mysql_system_tables.sql
mysql mysql < /usr/share/mysql/mysql_system_tables.sql

# 4. Restore events from backup
mysql mysql < events_backup.sql

Add these to your my.cnf to prevent future issues:

[mysqld]
event_scheduler=ON
skip-name-resolve  # reduces table locks
table_open_cache=4000  # for busy servers

Regular maintenance command:

mysqlcheck --optimize --all-databases

After repairs, verify with:

SELECT EVENT_SCHEMA, EVENT_NAME FROM INFORMATION_SCHEMA.EVENTS;
# And test dump:
mysqldump --events --all-databases > /dev/null

When running mysqldump with the --events flag, you encounter error #1557 indicating corruption in the Event Scheduler system tables. The specific error message:

mysqldump: Couldn't execute 'show events': Cannot proceed because system tables
     used by Event Scheduler were found damaged at server start (1577)

This typically occurs when the mysql.event table becomes corrupted. You can verify this by:

-- Check event table status
SHOW TABLE STATUS FROM mysql LIKE 'event';

-- Try querying events directly
SELECT * FROM mysql.event LIMIT 1;

If these commands return errors or show corrupted status, you've confirmed the issue.

First, stop the MySQL service:

sudo service mysql stop

Then run the repair process:

# For MyISAM engine (default for mysql.event in older versions)
myisamchk -r /var/lib/mysql/mysql/event.MYI

# For InnoDB engine (newer MySQL versions)
mysqlcheck --repair mysql event

If repair doesn't work, you can recreate the events table:

-- Backup existing events (if possible)
CREATE TABLE mysql.event_backup SELECT * FROM mysql.event;

-- Drop and recreate the table
DROP TABLE mysql.event;
SOURCE /usr/share/mysql/mysql_system_tables.sql

To avoid future corruption:

-- Regular maintenance
mysqlcheck --optimize --all-databases

-- Consider converting to InnoDB
ALTER TABLE mysql.event ENGINE=InnoDB;

For immediate backups while you fix the issue:

# Skip events during dump
mysqldump -hsql -uXXXX -pXXXX --skip-events --all-databases > backup.sql

# Alternative event export
SELECT CONCAT('CREATE EVENT IF NOT EXISTS ', name, ' ON SCHEDULE ', 
       definition) FROM mysql.event INTO OUTFILE '/tmp/events.sql';

Remember to restart MySQL after repairs:

sudo service mysql start