tencent cloud

TencentDB for DBbrain

How to Configure Slow SQL Analysis

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-07-23 17:41:43

Step 1: Enabling Slow Log Recording for a Self-built Database

First, check if slow log recording is enabled. Use the root account to log in to the self-built database instance and execute the following command:
mysql> show variables like 'slow%';
+---------------------+----------------------------------------+
| Variable_name | Value |
+---------------------+----------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /data/mysql/VM_83_217_centos-slow.log |
+---------------------+----------------------------------------+
As above, if the value of slow_query_log is ON, it indicates that it is enabled; if it is OFF, enable slow log recording by executing the following command:
mysql> set global slow_query_log='ON';
Note:
This command will become invalid after the instance restarts. To make this configuration persistent, modify the database instance configuration file (default configuration file: /etc/my.cnf) and add the following under mysqld:
root@xxx ~ # vim /etc/my.cnf
[mysqld]
slow_query_log=ON

Step 2: Modifying Slow Log File Access Permissions

After enabling slow log recording, ensure the agent can read the slow log file to use the slow SQL analysis feature normally.
First, execute the show variables like 'slow%' command on the database instance to check the location of the slow log file:
mysql> show variables like 'slow%';
+----------------------+----------------------------------------+
| Variable_name | Value |
+----------------------+----------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /data/mysql/VM_83_217_centos-slow.log |
+----------------------+----------------------------------------+
The value of slow_query_log_file is the location of the slow log file. Modify its parent directory permissions to be accessible and set the log file to readable:
root@xxx ~ # chmod 755 /data
For the above slow log file, its parent directories are /data/mysql and /data. Configure permissions for each directory.
root@xxx ~ # chmod 755 /data/mysql
Then set the log file to readable.
root@xxx ~ # chmod 644 /data/mysql/VM_83_217_centos-slow.log

Step 3: Enabling the Slow Log Collection Switch

1. Log in to the DBbrain console.
2. In the left sidebar, select Instance Management, and at the top, select the corresponding database.
3. Disable the Slow Log Collection switch for the database instance. If the switch can be enabled without errors, the slow log analysis configuration is completed.



Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan