260
The log file destination is enabled when both ``query_log_enabled`` and ``query_log_file_enabled`` are true (``SHOW VARIABLES`` lists ``ON`` and ``OFF`` instead of ``TRUE`` and ``FASLE``). When ``query_log_file_enabled`` is true, the ``query_log_file`` is open. When ``query_log_file_enabled`` is set false, the log file is closed. This is helpful if you want to rotate the log file.
260
The query log file destination is enabled when both ``query_log_enabled`` and ``query_log_file_enabled`` are true (``SHOW VARIABLES`` lists ``ON`` and ``OFF`` instead of ``TRUE`` and ``FASLE``). When ``query_log_file_enabled`` is true, the ``query_log_file`` is open. When ``query_log_file_enabled`` is set false, the query log file is closed. This is helpful if you want to rotate the query log file.
262
The log file is a plain text, structured file that is readable by humans and easily parsable by tools. It looks like:
262
The query log file is a plain text, structured file that is readable by humans and easily parsable by tools. It looks like:
264
264
.. code-block:: none
266
# 2011-05-15T01:48:17.814985
266
# start_ts=2011-05-15T01:48:17.814985
267
267
# session_id=1 query_id=6 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=1
268
268
# execution_time=0.000315 lock_time=0.000315 session_time=16.723020
271
271
set query_log_file_enabled=true;
273
# 2011-05-15T01:48:21.526746
273
# start_ts=2011-05-15T01:48:21.526746
274
274
# session_id=1 query_id=7 rows_examined=10 rows_sent=10 tmp_tables=0 warnings=0
275
275
# execution_time=0.000979 lock_time=0.000562 session_time=20.435445
281
281
Events are separated by a single ``#`` character. This record separator can be used by programs like :program:`awk` and :program:`perl` to easily separate events in a log.
283
The first line line of each event is a UTC/GMT timestamp with microsecond precision; the timezone cannot be changed. The second line has attributes with integer values. The third line has attributes with high-precision time values, always with six decimals places of precision. The fourth line has attributes with boolean values, either ``true`` or ``false``. The fifth line has attributes with string values, always double-quoted. Remaining lines are the query which can contain multiple lines, blank lines, et. The record separator marks the event of the event.
283
The first line of each event has UTC/GMT timestamps with microsecond precision; the timezone cannot be changed. The second line has attributes with integer values. The third line has attributes with high-precision time values, always with six decimals places of precision. The fourth line has attributes with boolean values, either ``true`` or ``false``. The fifth line has attributes with string values, always double-quoted. Remaining lines are the query which can contain multiple lines, blank lines, et. The record separator marks the event of the event.
285
As the example above demonstrates, the meta-format for each event in the query log is::
291
Parsing a query log file should be easy since the format is static, consistent, and follows
294
* Attribute-value pairs are on comment lines that begin with one ``#`` character followed
296
* Comment lines have one or more attribute-value pairs.
297
* Attribute-value pairs are separated by one space.
298
* Attribute names are lowercase with only characters ``a`` to ``z`` and ``_`` (underscore).
299
* Attribute names with suffix ``_ts`` have microsecond UTC/GMT timestamp values.
300
* Attribute names with suffix ``_time`` have values with an amount of time in seconds with
301
microsecond precision.
302
* One or more comment line precedes the query.
303
* A query is always printed; there are no "admin commands" or special queries.
304
* Every query is terminated by one ``#`` character followed by a newline (``\n``),
305
even the last query in the log file.
306
* There are no blank lines between events.
307
* Only events with this format are printed; there are no special or "fluff" lines.
285
309
Bugs and Limitations
286
310
--------------------