MYSQL enables slow query log, Enabling the Slow Query Log for MySQL or MariaDB can be a useful gadget to divide performance and capability issues affecting your worker. By observing requests that are particularly postponed in their completion, you can address them by recreating the application that triggers your inquiries. You can in like manner change the requests themselves to ensure that they are created as capably as could truly be anticipated.
For additional information about the MySQL moderate request log, read the MySQL 5.7 Reference Manual: The Slow Query Log documentation.
Engaging the slow inquiry log
MYSQL enable slow query log, Moderate inquiries can impact database execution and all-around specialist execution. The slow inquiry log remembers for MySQL enables you to log requests that outperform a predefined time limit. This uncommonly deals with the task of sorting out inefficient or drawn-out requests.
To engage the slow request sign in MySQL, follow these methods:
- Sign in to your specialist using SSH.
- At the request line, type the going with a request:
MySQL - u root - p
- Type the MySQL root secret word.
- To engage the drowsy inquiry log, type the going with request at the mysql> brief:
SET GLOBAL slow_query_log = 'ON';
- There are extra options that you can set for the torpid inquiry log:
Normally, when the inactive inquiry log is engaged, it logs any request that takes longer than 10 seconds to run. MYSQL enables a slow query log, to change this stretch, type the going with the request, displacing X with the time immediately:
SET GLOBAL long_query_time = X;
Normally, the dormant inquiry log record is arranged at/var/lib/mysql/hostname-slow.log. To change the log way or filename, type the going with the request, overriding way with the way to the record, and filename with the name of the log filename:
SET GLOBAL slow_query_log_file = '/way/filename';
- To confirm that the slow inquiry log is working exactly, log out of the MySQL program, and a while later log back in. (This reloads the gathering factors for the MySQL program.) Type the going with the request, overriding X with a value that is more important than the long_query_time setting:
SELECT SLEEP(X);
The relaxed request log record should contain information about the inquiry.
- Continue checking the torpid request log record to see which questions devour a huge lump of the day to run.
- Exactly when you are done examining, cripple the lazy inquiry log. MYSQL enable slow query log, to do this, run the MySQL program again, and subsequently type the going with a request:
SET GLOBAL slow_query_log = 'OFF';
Conclusion
MYSQL enables a slow query log, you have to simply engage the slow request log anyway long explore execution issues.