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

Solution to the problem of MySQL data delay jump

Today we analyzed another typical problem about d...

Modify the default scroll bar style in the front-end project (summary)

I have written many projects that require changin...

Implementation of react routing guard (routing interception)

React is different from Vue. It implements route ...

WeChat applet realizes horizontal and vertical scrolling

This article example shares the specific code for...

Vue.js cloud storage realizes image upload function

Preface Tip: The following is the main content of...

VMware ESXi installation and use record (with download)

Table of contents 1. Install ESXi 2. Set up ESXi ...

MySQL 5.7.17 installation and configuration graphic tutorial

Features of MySQL: MySQL is a relational database...

How to use nginx as a proxy cache

The purpose of using cache is to reduce the press...

VMware installation of Ubuntu 20.04 operating system tutorial diagram

Memo: Just experience it. Record: NO.209 This exa...

Full analysis of Vue diff algorithm

Table of contents Preface Vue update view patch s...

MySQL uses variables to implement various sorting

Core code -- Below I will demonstrate the impleme...

MYSQL master-slave replication knowledge points summary

An optimization solution when a single MYSQL serv...

Solution for using Baidu share on Https page

Since enabling https access for the entire site, ...

Summary of the differences between get and post requests in Vue

The operating environment of this tutorial: Windo...