I am seeing large mysqld.log files and wish to rotate them.
How do you rotate the mysqld.log file on my gateway?
Environment
Release : 9.x 10.x 11.x
Component : API Gateway
Cause
From time to time there are many issues that may cause you mysqld.log to grow in size and these files may need to be rotated.
Resolution
You will need to modify the /etc/logrotate.d/mysql file
# The log file name and location can be set in # /etc/my.cnf by setting the "log-error" option # in [mysqld] section as follows: # # [mysqld] # log-error=/var/log/mysqld.log # # For the mysqladmin commands below to work, root account # password is required. Use mysql_config_editor(1) to store # authentication credentials in the encrypted login path file # ~/.mylogin.cnf # # Example usage: # # mysql_config_editor set --login-path=client --user=root --host=localhost --password # # When these actions has been done, un-comment the following to # enable rotation of mysqld's log error. #
#/var/log/mysqld.log { # create 640 mysql mysql # notifempty # daily # rotate 5 # missingok # compress # postrotate # # just if mysqld is really running # if test -x /usr/bin/mysqladmin && \ # /usr/bin/mysqladmin ping &>/dev/null # then # /usr/bin/mysqladmin flush-logs # fi # endscript #}
You will need to uncomment everything below the "# enable rotation of mysqld's log error" line and add the following "--defaults-extra-file=/root/.my.cnf" after /usr/bin/mysqladmin
So it looks something like this:
# The log file name and location can be set in # /etc/my.cnf by setting the "log-error" option # in [mysqld] section as follows: # # [mysqld] # log-error=/var/log/mysqld.log # # For the mysqladmin commands below to work, root account # password is required. Use mysql_config_editor(1) to store # authentication credentials in the encrypted login path file # ~/.mylogin.cnf # # Example usage: # # mysql_config_editor set --login-path=client --user=root --host=localhost --password # # When these actions has been done, un-comment the following to # enable rotation of mysqld's log error. #
/var/log/mysqld.log { create 640 mysql mysql notifempty daily rotate 5 missingok compress postrotate # just if mysqld is really running if test -x /usr/bin/mysqladmin && \ /usr/bin/mysqladmin --defaults-extra-file=/root/.my.cnf ping &>/dev/null then /usr/bin/mysqladmin --defaults-extra-file=/root/.my.cnf flush-logs fi endscript }
Additional Information
In this file /usr/bin/mysqladmin uses roots password set in .my.cnf. You may need to use ls -la in the /root folder to see this file.
It is possible that this file may not exist on a software install and may need to be created. You would need to change the password to the password used by your root MySQL user.
# ls -la -rw-r--r-- 1 root root 25 Oct 12 2018 .my.cnf