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
This article example shares the specific code of ...
CocosCreator version 2.3.4 Dragon bone animation ...
How to check the status of Linux firewall 1. Basi...
My computer graphics card is Nvidia graphics card...
Both methods can be used to execute a piece of ja...
When the jsp that is jumped to after the struts2 a...
Insert image tag <IMG> The colorful web page...
introduction With the widespread popularity of In...
the difference: 1. InnoDB supports transactions, ...
The Swap partition of the Linux system, that is, ...
When encapsulating Vue components, I will still u...
When we work in a terminal or console, we may not...
Using iframes can easily call pages from other we...
<br />When we design web pages, we always en...
MariaDB database management system is a branch of...