As you have seen in the previous chapters, you can set the parameters by connecting to MySQL and executing the SET
command.
There are two types of variables based on the scope of the variable:
- Global: Applies to all the new connections
- Session: Applies only to the current connection (session)
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;