tencent cloud

TencentDB for DBbrain

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Strengths
Use Cases
Feature List
Region List
Purchase Guide
Operation Guide
Cloud Access Management
Self-Built Database Access
Instance Overview
Instance Management
Monitoring and Alarms
Health Report and Kill Session Report Management
MySQL/TDSQL-C for MySQL Performance Optimization
TDSQL for MySQL/MariaDB Performance Optimization
Distributed cache database (Distributed Cache) diagnostic optimization
MongoDB Performance Optimization
Full-Link Analysis
Practical Tutorial
Fixing High CPU Utilization on MySQL Instance
Fixing Lock Conflict on MySQL Instance
How to Address High CPU Utilization Issues in Distributed Cache Instances
Fixing High CPU Utilization in MongoDB Instance
Fixing Short Node Oplog Retention Period in MongoDB Instance
API Documentation
History
Introduction
Introduction
API Category
Making API Requests
Session Killing APIs
Exception Detection APIs
Other APIs
Redis related APIs
Health Report Email Sending APIs
Space Analysis APIs
Slow Log Analysis APIs
Security Audit APIs
Database Audit APIs
Data Types
Error Codes
DBbrain APIs 2019-10-16
FAQs
Self-Built Database Issues
MySQL Performance
Product
Service Level Agreement
Glossary
Contact Us

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