Introduction
This article aims to provide instructions on how to enable the MySQL general query log. You might want to enable the general query log if you need to see what is occurs in MySQL or what queries run.
Procedure
1. Consult with your version of MySQL's reference manual on the general query log before applying changes.
2. In SSH as the root user, open the /etc/my.cnf file with your preferred text editor.
3. Locate a line containing "[mysqld]" and add these two lines somewhere underneath it to set the "general_log" and "general_log_file" variables.
Please note the general_log_file variable is optional if it is already set in mysql.
# nano /etc/my.cnf
[mysqld] ... general_log=1 general_log_file=query.log
Please note that enabling the general query log option in MySQL will write a large amount of data, so you may experience IO issues or suffer from a large amount of disk space used. You will want to monitor the usage and potentially set up a rotation of the log with a tool such as logrotate.
3. Save this file (CTRL + o and CTRL + x if using nano), then run the following script in SSH as root to restart MySQL to load the change:
/usr/local/cpanel/scripts/restartsrv_mysql
4. To confirm the variable is set in MySQL, run the following in SSH as root.
[root@server ~]cPs# mysql -e "SELECT @@GLOBAL.general_log;" +----------------------+ | @@GLOBAL.general_log | +----------------------+ | 1 | +----------------------+
Please note that a value of 1, as seen above, indicates general log is enabled.
Additional Resources
How to edit a file on command-line
MySQL 5.7 - The General Query Log
Comments
0 comments
Article is closed for comments.