Reasons and solutions for slow MySQL query stuck in sending data

Reasons and solutions for slow MySQL query stuck in sending data

Because I wrote a Python program and intensively operated a Mysql library. When the amount of data was not large, I didn't notice it was very slow. Later, it became slower and slower. I thought it was just because of the large amount of data. But later it became so slow that I couldn't bear it. I checked for a long time and used all the indexes that could be used. It still took 3 to 4 seconds to execute once, which was unbearable.

So I cached all the queries that could be cached using redis, which greatly accelerated the application.

But there are still some things that cannot be cached, or in other words, there is no way to cache them if the results are different every time you query them. Using Navicat's query overview, we can see that the stuck part is in the Sending data section, which takes 3.5 seconds and accounts for 99% of the query time.

I checked some information online and found that some of them were due to problems with SQL statements, but I did not use varchar or the in method at all.

So I thought maybe the table was too large and might not be cached in the memory, so I checked the memory occupied by the mysqld process, which was only more than 50M, which was obviously too little. The actual capacity of the table was more than 200M, which can be seen in the object column of navicat. It should be that each query is read from the disk, so it is very time-consuming. So I checked the disk IO of win10 and found that it was indeed the case. The disk IO reached 100%, and it was a solid-state drive, reading about 80M per second. No wonder it was so slow.

So I checked the mysql configuration file and found that there was a configuration of only 32M. I adjusted it to 512M and restarted mysql. This time the time was reduced from 3.5 seconds to 0.76 seconds.

The configuration items are:

innodb_buffer_pool_size=32M

This is the default for MySQL 5.7. Change it to 512 or 1024 and restart, depending on your hardware configuration.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to solve the slow speed of MySQL Like fuzzy query
  • MySQL slow query method and example
  • Detailed explanation of the reason why the MySQL 5.7 slow query log time is 8 hours behind the system time
  • MySQL slow query operation example analysis [enable, test, confirm, etc.]
  • Causes and solutions for slow MySQL query speed and poor performance
  • Causes and solutions for slow MySQL queries
  • Mysql slow query optimization method and optimization principle
  • How to enable the slow query log function in MySQL
  • Basic usage tutorial of MySQL slow query log
  • Mysql sql slow query monitoring script code example

<<:  Summary of Linux file directory management commands

>>:  Working principle and implementation method of Vue instruction

Recommend

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

Analysis and solution of MySQL connection throwing Authentication Failed error

[Problem description] On the application side, th...

About ROS2 installation and docker environment usage

Table of contents Why use Docker? Docker installa...

How to set the position of the block element in the middle of the window

How to set the position of the block element in t...

Solution to the failure of docker windows10 shared directory mounting

cause When executing the docker script, an error ...

CSS style to center the HTML tag in the browser

CSS style: Copy code The code is as follows: <s...

The difference between html form submission action and url jump to actiond

The action of the form is different from the URL j...

Encapsulation method of Vue breadcrumbs component

Vue encapsulates the breadcrumb component for you...

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

How to implement n-grid layout in CSS

Common application scenarios The interfaces of cu...

How to view and optimize MySql indexes

MySQL supports hash and btree indexes. InnoDB and...

Use crontab to run the script of executing jar program regularly in centOS6

1. Write a simple Java program public class tests...

MySQL 8.0.14 installation and configuration method graphic tutorial

This article records the installation and configu...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...