Configuration and usage related to MySQL slow query log
The MySQL slow query log provides query information that exceeds the specified time threshold, providing a main reference for performance optimization. It is a very practical function.
The opening and configuration of the MySQL slow query log is very simple and can be specified Recorded files (or tables), exceeded time thresholds, etc. can be recorded to slow sql.
To be honest, compared with sqlserver's trace or extended events (although the role of these two is not only that), MySQL's configuration It always gives people a very refreshing feeling.
1. To open the slow query log, under normal circumstances, you only need to add the slow_query_log = 1 configuration in the configuration file, that is, to open the slow query log. If slow_query_log_file is not specified, a file with the host name + will be automatically generated. 'slow'.log file
2. By default, the time threshold for recording slow queries is 10s
By default, slow_query_log is specified = 1, when you start MySQL, you can turn on slow queries, and automatically generate a default file with the host name ++'slow'.log to record slow queries that exceed execution for more than 10 seconds.
You can also explicitly specify the slow query log file name (it will be automatically created if it does not exist) and the time threshold for recording slow queries (non-default 10s).
Note that when specifying long_query_time in the configuration file, no time unit is required, only a value is required, such as 1 represents 1s. If the time unit is specified, the service will not be able to start up.
The following is an example of slow sql recorded in the log file
3. Record the slow query log to Table
Configuration: You need to add a log_output configuration so that slow queries can be recorded in the table
There is a default slow_log table under the mysql library , you can directly set slow_query_log_file = slow_log to record the slow query log into the table.
The recorded slow sql is as follows. It can be found that sql_text is a binary information, not the original sql text
It can be converted through the CONVERT function Just one click.
About the difference between slow queries recorded in log files and tables:
1. Slow queries are recorded in log files and tables, and there is no difference in the records themselves. Large, if it is recorded in the table, the execution time information of the slow query cannot be accurate to the subtle,
2. If the slow query information is recorded in the table, it is convenient for query, but because it is structured data, it may It will be a little slower than recording in a slow query log file (flat text file) (personal guess). If it is recorded to a file, the mysqldumpslow tool needs to be parsed.
3. Slow queries do not record queries that fail to execute. For example, long_query_time is set to 10 (10 seconds). If a query exceeds 10 seconds, but fails to execute due to other reasons, MySQL's slow queries will not be recorded. This query information.
The above is the detailed content of Configuration and usage related to MySQL slow query log. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
