ERROR 1182 occurs when MySQL cannot rotate or flush its binary, relay, or general query logs due to disk space issues, file permission problems, or I/O errors. Fix by freeing disk space, correcting log directory permissions, or resolving filesystem errors, then retry the FLUSH LOGS operation.
ERROR 1182 (HY000: ER_ERROR_DURING_FLUSH_LOGS) is a runtime error that occurs when the MySQL server attempts to flush or rotate its logs (binary logs, relay logs, general query log, or slow query log) but encounters an underlying operating system or filesystem error. This prevents the server from creating new log files or closing and reopening existing ones. The error indicates a system-level problem rather than a SQL syntax issue, and it often leaves logging in an inconsistent state if the operation fails mid-process.
Determine how much disk space is available where the log files are stored.
For Linux/Unix:
df -h /var/log
df -h /var/lib/mysqlCheck current log file sizes:
du -sh /var/log/mysql/
du -sh /var/lib/mysql/*.log*If available space is critically low (< 5% free), this is likely the cause. Proceed to Step 2 to free disk space.
If disk space is low, remove old log files and binaries:
1. Purge old binary logs (if binary logging is enabled):
SHOW BINARY LOGS;
PURGE BINARY LOGS BEFORE DATE_SUB(NOW(), INTERVAL 7 DAY);2. Remove old MySQL general or slow query logs (if they're not in rotation):
sudo rm -f /var/log/mysql/mysql.log*
sudo rm -f /var/log/mysql/mysql-slow.log*3. Clean up system logs if they share the partition:
sudo find /var/log -name "*.gz" -mtime +30 -delete
sudo journalctl --vacuum=30d4. Expand storage if you need more capacity long-term:
- Add a new disk or extend the existing partition
- Configure MySQL to use a separate log directory on another volume
Check that the MySQL process has write access to log directories.
For Linux/Unix, check current permissions:
ls -ld /var/log/mysql
ls -l /var/log/mysql/The MySQL user (typically 'mysql') must own the directory or have write permissions:
sudo chown -R mysql:mysql /var/log/mysql
sudo chmod 750 /var/log/mysql
sudo chmod 640 /var/log/mysql/*.logOn systems where the error log is in /var/log directly:
sudo touch /var/log/mysqld.log
sudo chown mysql:mysql /var/log/mysqld.log
sudo chmod 640 /var/log/mysqld.logFor Docker containers, ensure the entrypoint creates log files with proper ownership before MySQL starts.
If using SELinux, verify the context is correct for log directories:
ls -Z /var/log/mysql/
# Should show a context like: mysql_log_t or var_log_tIf the context is wrong, restore it:
sudo restorecon -R /var/log/mysqlIf using AppArmor, check the MySQL profile:
sudo aa-status | grep mysqlCheck the AppArmor denial log:
sudo grep DENIED /var/log/syslog | grep mysql | tail -10If denials exist, the profile may need to be updated to allow the log path.
Review the MySQL error log to see the exact operating system error code:
For Linux/Unix (default locations):
tail -30 /var/log/mysql/error.log
# or
tail -30 /var/log/mysqld.logFor Windows:
type "C:\ProgramData\MySQL\MySQL Server 8.0\Data\hostname.err"Look for lines like:
ERROR 1182: Got error during FLUSH_LOGS
... error 13: Permission denied
... error 28: No space left on deviceThe error code (13, 28, etc.) tells you the root cause.
Once you've fixed the underlying issue (disk space, permissions, or SELinux), attempt the flush again:
FLUSH LOGS;Or using the command line:
mysqladmin flush-logsIf it still fails, check the error log again for a different OS error code. You may need to restart MySQL for some permission changes to take effect:
sudo systemctl restart mysqlVerify logging is active:
SHOW VARIABLES LIKE '%log%';Binary Log Recovery: If binary logging is critical and flush fails repeatedly, consider temporarily disabling it until root cause is fixed:
[mysqld]
skip-log-bin # Temporarily disable to testLog Rotation with Logrotate: On Linux, logrotate can send SIGHUP to trigger log reopening without explicit FLUSH LOGS:
/var/log/mysql/mysql-slow.log {
daily
rotate 7
compress
delaycompress
notifempty
create 640 mysql mysql
sharedscripts
postrotate
/usr/bin/mysqladmin flush-logs > /dev/null 2>&1 || true
endscript
}Alternative Signal to FLUSH LOGS: If FLUSH LOGS hangs or repeatedly fails, use SIGUSR1 instead, which flushes error, general, and slow query logs without affecting binary logs:
kill -SIGUSR1 $(pgrep mysqld)Replication Considerations: If this server is a MySQL replica, binary log rotation failures can break replication. Ensure the relay log directory has sufficient space and permissions too. On a primary server, monitor the binary log size to prevent unbounded growth:
[mysqld]
max_binlog_size = 100M # Rotate after 100MB (default)Filesystem I/O Errors: If the OS error is something like errno 5 (EIO), the underlying filesystem may be degraded. Run filesystem checks:
sudo fsck -n /dev/sdXY # Check without repair
sudo fsck /dev/sdXY # Repair if needed (run offline)EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL