O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required