Mysql open query log

First of all, it is explained that most of the configurations below can be directly executed by command dynamic configuration, which is suitable for the situation that mysql cannot be restarted. For example, the online server cannot be easily restarted, but the cooperation will fail after restarting. Another is to directly modify the configuration file, and the configuration will be permanent after restarting mysql. efficient.

1. Open general_log:

Execute in the mysql command line or client management tool: SHOW VARIABLES LIKE "general_log%";

result:

                general_log OFF
                general_log_file /var/lib/mysql/localhost.log

OFF means logging is not enabled

Execute open log and log path and log file name respectively

            SET GLOBAL general_log_file = '/var/lib/mysql/localhost.log';
            SET GLOBAL general_log = 'ON';

Also note

All sql executed at this time will not be recorded for easy viewing, but if you restart mysql, the recording will stop and need to be reset

            SHOW VARIABLES LIKE "log_output%";

If it is NONE, it means no output. If it is a file, it is output to the log file. If it is a table, it is output to the general_log table in the mysql library. This is configured on demand, and the setting method is as follows:

            SET GLOBAL log_output='TABLE,FILE'

2. Turn on slow query

            slow-query-log=1 --Enable slow query
            slow_query_log_file="103-54-slow.log" --Slow query log file name, the default is the same path as the data directory
            long_query_time=1 --It is considered to be a slow query if it exceeds 1s

3. Turn on the SQL filter configuration that does not use an index:

            log_queries_not_using_indexes 

Just add this line directly to the configuration file or:

            log_queries_not_using_indexes =1

restart mysql.

Article from https://blog.csdn.net/u014180504/article/details/73826679

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325022295&siteId=291194637