How to enable MySQL Query Log?

后端 未结 14 1388
渐次进展
渐次进展 2020-11-22 09:38

How do I enable the MySQL function that logs each SQL query statement received from clients and the time that query statement has submitted? Can I do that in phpmyadmin or N

相关标签:
14条回答
  • 2020-11-22 10:24

    First, Remember that this logfile can grow very large on a busy server.

    For mysql < 5.1.29:

    To enable the query log, put this in /etc/my.cnf in the [mysqld] section

    log   = /path/to/query.log  #works for mysql < 5.1.29
    

    Also, to enable it from MySQL console

    SET general_log = 1;
    

    See http://dev.mysql.com/doc/refman/5.1/en/query-log.html

    For mysql 5.1.29+

    With mysql 5.1.29+ , the log option is deprecated. To specify the logfile and enable logging, use this in my.cnf in the [mysqld] section:

    general_log_file = /path/to/query.log
    general_log      = 1
    

    Alternately, to turn on logging from MySQL console (must also specify log file location somehow, or find the default location):

    SET global general_log = 1;
    

    Also note that there are additional options to log only slow queries, or those which do not use indexes.

    0 讨论(0)
  • 2020-11-22 10:24

    To enable the query log in MAC Machine:

    Open the following file:

    vi /private/etc/my.cnf
    

    Set the query log url under 'mysqld' section as follows:

    [mysqld]
    
    general_log_file=/Users/kumanan/Documents/mysql_query.log
    

    Few machine’s are not logging query properly, So that case you can enable it from MySQL console

    mysql> SET global general_log = 1;
    
    0 讨论(0)
提交回复
热议问题