Difference between revisions of "MySQL Query logging"

From Notes_Wiki
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Query logging=
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Mariadb configuration|MariaDB configuration]] > [[MySQL Query logging]]


==Logging all queries==
==Logging all queries==
Line 23: Line 23:
*'<tt>log_slow_queries</tt>' is used to log all queries which take more than '<tt>long_query_time</tt>' seconds to execute. The minimum value of this parameter is 2, as mysql measures time with second accuracy.
*'<tt>log_slow_queries</tt>' is used to log all queries which take more than '<tt>long_query_time</tt>' seconds to execute. The minimum value of this parameter is 2, as mysql measures time with second accuracy.
*'<tt>log_long_format</tt>' will log additional information like which queries are not using indexes at all or not using indexes properly, etc.
*'<tt>log_long_format</tt>' will log additional information like which queries are not using indexes at all or not using indexes properly, etc.
In newer versions use:
<pre>
long_query_time = 5
slow_query_log = 1
slow_query_log_file = /tmp/mysql_slow.log
</pre>




Line 28: Line 35:




Back to [[Mysql configuration]]
 
 
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Mariadb configuration|MariaDB configuration]] > [[MySQL Query logging]]

Latest revision as of 02:54, 5 March 2022

Home > CentOS > CentOS 6.x > MariaDB configuration > MySQL Query logging

Logging all queries

We can log all queries that are received by server (even that have incorrect syntax) using 'log' option in '[mysqld]' section

[mysqld]
log

This can be very helpful on development machines for debugging.


Logging slow queries

Logging all queries can be problematic on production servers. Hence on production servers we can use:

long_query_time = 5
log_slow_queries
log_long_format

Here:

  • 'log_slow_queries' is used to log all queries which take more than 'long_query_time' seconds to execute. The minimum value of this parameter is 2, as mysql measures time with second accuracy.
  • 'log_long_format' will log additional information like which queries are not using indexes at all or not using indexes properly, etc.

In newer versions use:

long_query_time = 5
slow_query_log = 1
slow_query_log_file = /tmp/mysql_slow.log


More information about configurable parameters of mysql can be found in '/usr/share/doc/mysql-server-<version>'.



Home > CentOS > CentOS 6.x > MariaDB configuration > MySQL Query logging