How to enable MySQL Query Log?

后端 未结 14 1405
渐次进展
渐次进展 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:00

    In phpMyAdmin 4.0, you go to Status > Monitor. In there you can enable the slow query log and general log, see a live monitor, select a portion of the graph, see the related queries and analyse them.

    0 讨论(0)
  • 2020-11-22 10:01
    // To see global variable is enabled or not and location of query log    
    SHOW VARIABLES like 'general%';
    // Set query log on 
    SET GLOBAL general_log = ON; 
    
    0 讨论(0)
  • 2020-11-22 10:03

    This was already in a comment, but deserves its own answer: Without editing the config files: in mysql, as root, do

    SET global general_log_file='/tmp/mysql.log'; 
    SET global log_output = 'file';
    SET global general_log = on;
    

    Don't forget to turn it off afterwards:

    SET global general_log = off;
    
    0 讨论(0)
  • 2020-11-22 10:03

    You can disable or enable the general query log (which logs all queries) with

    SET GLOBAL general_log = 1 # (or 0 to disable)
    
    0 讨论(0)
  • 2020-11-22 10:03

    for mysql>=5.5 only for slow queries (1 second and more) my.cfg

    [mysqld]
    slow-query-log = 1
    slow-query-log-file = /var/log/mysql/mysql-slow.log
    long_query_time = 1
    log-queries-not-using-indexes
    
    0 讨论(0)
  • 2020-11-22 10:06

    I also wanted to enable the MySQL log file to see the queries and I have resolved this with the below instructions

    1. Go to /etc/mysql/mysql.conf.d
    2. open the mysqld.cnf

    and enable the below lines

    general_log_file        = /var/log/mysql/mysql.log
    general_log             = 1
    
    1. restart the MySQL with this command /etc/init.d/mysql restart
    2. go to /var/log/mysql/ and check the logs
    0 讨论(0)
提交回复
热议问题