
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can I enable MySQL slow query log without restarting MySQL?
We can enable the MySQL slow query log with the help of SET statement.
The following is the syntax.
SET GLOBAL slow_query_log = 'Value';
In the above syntax, value can be filled with ON/OFF. To enable slow query log, let us see the query.
mysql> SET GLOBAL slow_query_log = 'ON'; Query OK, 0 rows affected (0.00 sec)
To check if the slow query is ON, implement the following query −
mysql> SHOW GLOBAL VARIABLES LIKE 'slow\_%';
Here is the output.
+---------------------+--------------------------+ | Variable_name | Value | +---------------------+--------------------------+ | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | DESKTOP-QN2RB3H-slow.log | +---------------------+--------------------------+ 3 rows in set (0.00 sec)
We have set the slow query time in seconds because if any query is beyond the given seconds, it will enter into the slow query log file.
We can also set the seconds. Here is the query to set the seconds.
mysql> SET GLOBAL long_query_time = 20; Query OK, 0 rows affected (0.00 sec)
To check if the time is inserted.
mysql> SHOW GLOBAL VARIABLES LIKE 'long_query_time';
Here is the output of the above query.
+-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 20.000000 | +-----------------+-----------+ 1 row in set (0.00 sec)
After doing the above task, we need to flush logs.
mysql> FLUSH LOGS; Query OK, 0 rows affected (0.25 sec)
Note − We can permanently disable it with the help of my.cnf file. Set slow_query_log = 0; to disable.
- Related Articles
- How to enable MySQL Query Log?
- How can I install or enable innoDB in MySQL?
- How can I display MySQL query result vertically?
- How can I stop a running MySQL query?
- How can I stop running a MySQL query?
- How can I check how much time MySQL query, without printing it on the console, is taking?
- How can we ENABLE AND DISABLE a particular MySQL event?
- How can I add one day to DATETIME field in MySQL query?
- How can I avoid too many OR statements in a MySQL query?
- Enable MySQL Compression
- How can I get maximum and minimum values in a single MySQL query?
- How can I enhance my select query to make it faster in MySQL?
- How should I enable LOAD DATA LOCAL INFILE in my.cnf in MySQL?
- Can I get Age using BirthDate column in a MySQL query?
- How can I start MySQL Server?

Advertisements