Friends who are doing development, especially those who have contact with MySQL, will sometimes encounter MySQL queries that are very slow. Of course, I mean large amounts of data in the millions or tens of millions, not just dozens of entries. Let's take a look at the solution to slow queryDevelopers are often found checking for statements without indexes or limit n. These statements can have a significant impact on the database. For example, a large table with tens of millions of records needs to be scanned completely, or filesort is performed continuously, which affects the IO of the database and server. This is the situation on the mirror library. When it comes to the online database, in addition to statements without indexes and statements without limit, there is another problem: too many MySQL connections. Speaking of this, let’s take a look at our previous monitoring practices:
I used to think that these monitorings were perfect, but now after deploying MySQL node process monitoring, I have discovered many drawbacks.
So how do we solve and query these problems? When it comes to troubleshooting and finding performance bottlenecks, the easiest problems to find and solve are slow MYSQL queries and queries without indexes. Method 1 : I am currently using this method. Haha, I prefer the immediacy of this method. Mysql versions 5.0 and above can support recording SQL statements that execute slowly. mysql> show variables like 'long%'; Note: This long_query_time is used to define how many seconds slower a query is considered a "slow query". +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row in set (0.00 sec) mysql> set long_query_time=1; Note: I set it to 1, which means that any query that takes more than 1 second to execute is considered a slow query. Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'slow%'; +---------------------+---------------+ | Variable_name | Value | +---------------------+---------------+ | slow_launch_time | 2 | | slow_query_log | ON | Note: whether to turn on logging | slow_query_log_file | /tmp/slow.log | Note: where to set it to+---------------------+---------------+ 3 rows in set (0.00 sec) mysql> set global slow_query_log='ON' Note: Turn on logging Once the slow_query_log variable is set to ON, mysql starts logging immediately. Method 2 : mysqldumpslow command
Some people suggest that we set up the mysql configuration file When adjusting This concludes this article on MySQL query optimization, the causes of slow queries and solutions. For more relevant MySQL query optimization content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Cross-host communication between docker containers-overlay-based implementation method
>>: Analysis of the principle of centering elements with CSS
A few days ago, I exchanged some knowledge about ...
1. Download, install and activate CLion Just foll...
In SQL, GROUP BY is used to group data in the res...
This article shares with you the graphic tutorial...
VirtualBox is a free and open source virtualizati...
This article shares a dynamic loading progress ba...
Table of contents 1. What is multi-instance 2. Pr...
This article shares the specific code of JavaScri...
Table of contents 1. switch 2. While Loop 3. Do/W...
Regarding the high availability solutions for Ora...
From: https://blog.csdn.net/qq_44761243/article/d...
Table of contents 1. Get the value of browser coo...
In daily work, we sometimes run slow queries to r...
1. Create an empty directory $ cd /home/xm6f/dev ...
Table of contents 1. Two setState, how many times...