How to do it...

For example, if you want to log all queries that are slower than one second, you can execute:

mysql> SET GLOBAL long_query_time = 1;

To make the changes persistent across restarts use:

mysql> SET PERSIST long_query_time = 1;Query OK, 0 rows affected (0.01 sec)

Or:

mysql> SET @@persist.long_query_time = 1;Query OK, 0 rows affected (0.00 sec)

The persisted global system variable settings are stored in mysqld-auto.cnf which is located in data directory.

Suppose you want to log queries only for this session and not for all the connections. You can use the following command:

mysql> SET SESSION long_query_time = 1;

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.