1. IntroductionBy enabling the slow query log, MySQL can record query statements that exceed the specified time. By locating and analyzing performance bottlenecks, the performance of the database system can be better optimized. 2. Parameter Description 3. Setup steps1. View slow query related parameters mysql> show variables like 'slow_query%'; +---------------------------+----------------------------------+ | Variable_name | Value | +---------------------------+----------------------------------+ | slow_query_log | OFF | | slow_query_log_file | /mysql/data/localhost-slow.log | +---------------------------+----------------------------------+ mysql> show variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 2. Setting method Method 1: Global variable setting Set the slow_query_log global variable to "ON" mysql> set global slow_query_log='ON'; Set the location where the slow query log is stored mysql> set global slow_query_log_file='/usr/local/mysql/data/slow.log'; If the query exceeds 1 second, it will be recorded mysql> set global long_query_time=1; Method 2: Configuration file settings Modify the configuration file my.cnf and add it below [mysqld]. [mysqld] slow_query_log = ON slow_query_log_file = /usr/local/mysql/data/slow.log long_query_time = 1 3. Restart MySQL service service mysqld restart 4. Check the parameters after setting mysql> show variables like 'slow_query%'; +---------------------+--------------------------------+ | Variable_name | Value | +---------------------+--------------------------------+ | slow_query_log | ON | | slow_query_log_file | /usr/local/mysql/data/slow.log | +---------------------+--------------------------------+ mysql> show variables like 'long_query_time'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 1.000000 | +-----------------+----------+ 4. Testing1. Execute a slow query SQL statement mysql> select sleep(2); 2. Check whether slow query logs are generated ls /usr/local/mysql/data/slow.log If the log exists, MySQL slow query setting is enabled successfully! This is the end of this article about MYSQL slow query and log examples. For more relevant MYSQL slow query and log content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: 5 super useful open source Docker tools highly recommended
>>: W3C Tutorial (15): W3C SMIL Activities
Table of contents 1. Problem 2. Solution 2.1 Pagi...
HTML web page list tag learning tutorial. In HTML ...
Tomcat defines multiple ClassLoaders internally s...
The mathematical expression calc() is a function ...
<style type="text/css"> Copy code ...
In the process of writing HTML, we often define mu...
Since myeclipse2017 and idea2017 are installed on...
Table of contents Array deduplication 1. from() s...
Platform deployment 1. Install JDK step1. Downloa...
What is an index? An index is a data structure th...
CSS transformations, while cool, have not yet bee...
I installed it in msi format, mainly to see the m...
Most people have heard of the concept of server-s...
1. Install less dependency: npm install less less...
1. Transaction characteristics (ACID) (1) Atomici...