Warning
Error Code:
1868
MySQL Error 1868: Active Log File Not Purged
Description
Error 1868 indicates that MySQL attempted to purge a log file, but the operation failed because the specified file is currently being used as an active transaction log. This typically occurs during automated log management or manual cleanup attempts when the system cannot safely remove a log vital for ongoing operations.
Error Message
file %s was not purged because it is the active log file.
Known Causes
3 known causesAttempting to Purge Active Binary Log
The most common cause is issuing a `PURGE BINARY LOGS` command that inadvertently includes or targets the binary log file presently in use by the MySQL server.
Purging Active Relay Log on Replica
On a replica server, this error can occur when attempting to purge relay logs, and the specified log file is currently being written to or read from by the replica's SQL thread.
Misconfigured Log Rotation Script
Automated log rotation scripts or third-party tools may be configured to purge logs without properly checking if they are still active, leading to this error.
Solutions
3 solutions available1. Graceful Shutdown and Restart easy
Allow MySQL to properly close and reopen its log files.
1
Gracefully shut down the MySQL server. This ensures that any ongoing operations are completed and log files are properly managed.
sudo systemctl stop mysql # For systemd-based systems (e.g., Ubuntu 15.04+, CentOS 7+)
# or
sudo service mysql stop # For older SysVinit systems
2
Wait for a few moments to ensure the shutdown process is complete.
3
Start the MySQL server again. This will trigger MySQL to re-initialize and create new active log files if necessary.
sudo systemctl start mysql # For systemd-based systems
# or
sudo service mysql start # For older SysVinit systems
2. Forcefully Rotate Binary Logs (if applicable) medium
Manually trigger a rotation of binary logs, which might resolve the issue if it's related to binary log management.
1
Connect to the MySQL server using the MySQL client.
mysql -u your_user -p
2
Execute the `FLUSH LOGS` command. This command forces MySQL to close all current log files and open new ones. It's particularly useful if you are using binary logging.
FLUSH LOGS;
3
Exit the MySQL client.
EXIT;
4
Verify that the error message is no longer appearing in your MySQL error logs.
3. Check and Clean Up Old Binary Log Files medium
Manually remove old, unneeded binary log files to prevent conflicts.
1
Identify the directory where your MySQL binary logs are stored. This is usually specified by the `log_bin` variable in your `my.cnf` or `my.ini` configuration file.
2
List the binary log files in that directory. Look for files with a `.bin` or `.log` extension, followed by numbers.
ls -l /path/to/your/mysql/log/directory/*.bin
3
If you have binary logs that are older than your `expire_logs_days` setting (or if you don't have `expire_logs_days` set and they are very old), you can manually remove them. **Proceed with caution and ensure you have backups if necessary.**
rm /path/to/your/mysql/log/directory/mysql-bin.000001
4
After cleaning up, restart the MySQL server to ensure it re-reads its log configuration.
sudo systemctl restart mysql # For systemd-based systems
# or
sudo service mysql restart # For older SysVinit systems