Displays the slow query status and log directory
show variables like '%slow_query_log%';
Copy the code
+---------------------+--------------------------------------+
| Variable_name | Value |
+---------------------+--------------------------------------+
| slow_query_log | OFF |
| slow_query_log_file | /var/lib/mysql/9e6bec7d7160-slow.log |
+---------------------+--------------------------------------+
Copy the code
Enabling Slow Query
Description: 1 open; 0 close;
set global slow_query_log = 1;
Copy the code
Display slow query threshold in seconds
By default, a log is generated only when the execution time exceeds 10 seconds
show variables like '%long_query%';
Copy the code
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+| long_query_time | | + 10.000000-----------------+-----------+
Copy the code
Set the slow query threshold
Note: You need to restart the mysql client to get the latest values
set global long_query_time = 0.8;
Copy the code
Check whether deadlock logging is enabled
show variables like "%innodb_print_all_deadlocks%";
Copy the code
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_print_all_deadlocks | OFF |
+----------------------------+-------+
Copy the code
Enable record deadlock
set global innodb_print_all_deadlocks=1
Copy the code