/var/log full because of very large mysqld.log file

Document ID : KB000106971
Last Modified Date : 21/02/2019
Show Technical Document Details
How to prevent the mysqld.log file to grow to large and fill up the /var/log?
To disable the logs, you would need to modify the my.cnf file
(see https://dev.mysql.com/doc/refman/5.7/en/error-log-unix.html and https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html)

Another option would be to rotate the logs:
you need to use a tool called logrotate, which is designed to ease administration of systems that generate large numbers of log files.
It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.
With this tool you keep logs longer with less disk space. https://www.cyberciti.biz/faq/how-do-i-rotate-log-files/

There is also the option to flush the log by this command:
#mysqladmin flush-logs
This will
- close any existing binlog files and open a new one with the next sequence number. You can then delete the old ones manually.
- it will close and reopen any other mysql log file. To force the creation of new files you will need to move the old files. For the /var/log/mysqld.log file you must manually create the new log file with the proper ownership after renaming the original log file
You can use the following set of commands:
shell> cd mysql-data-directory 
shell> mv mysql.log mysql.old 
shell> mv mysql-slow.log mysql-slow.old 
shell> mv /var/log/mysqld.log /var/log/mysqld.log.old 
shell> install -omysql -gmysql -m0644 /dev/null /var/log/mysqld.log 

shell> mysqladmin flush-logs
After this you can backup and delete the old files. For more details, exceptions and background see also: https://dev.mysql.com/doc/refman/5.7/en/log-file-maintenance.html