How to enable MySQL Query Log?

后端 未结 14 1394
渐次进展
渐次进展 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.

提交回复
热议问题