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
nohup command: If you are running a process and y...
1. Introduction to MMM: MMM stands for Multi-Mast...
This is the effect to be achieved: You can see th...
html <div class="totop" v-show="...
Table of contents 1. Basic environment configurat...
Preface The mysql module (project address is http...
Before further analyzing why MySQL database index...
Everyone may be familiar with the select drop-dow...
Dockerfile is a file used to build a docker image...
Pseudo-arrays and arrays In JavaScript, except fo...
Usually in project development, we have to deal wi...
Table of contents 1. Project requirements 2. Docu...
Overview of MySQL MySQL is a relational database ...
This article shares the Vue calculation property ...
Recently, there is a particularly abnormal busine...