Detailed summary of MySQL and connection-related timeouts

Detailed summary of MySQL and connection-related timeouts

MySQL and connection related timeouts

Preface:

Today a colleague asked me why the session was always disconnected when querying the MySQL database when the amount of data was large. At first I thought it was a MySQL connection timeout issue, but it turned out to be due to network instability.

The following summarizes the timeouts related to connections

slave-net-timeout

The number of seconds to wait for more data from the master before the slave considers the connection broken, aborts the read, and tries to reconnect. The first retry occurs immediately after the timeout. The interval between retries is controlled by the MASTER_CONNECT_RETRY option for the CHANGE MASTER TO statement, and the number of reconnection attempts is limited by the --master-retry-count option. The default is 3600 seconds (one hour).
When the slave thinks there is a problem with the connection to the master, it waits N seconds, then disconnects and reconnects to the master.

net_read_timeout :

The number of seconds to wait for more data from a connection before aborting the read. When the server is reading from the client, net_read_timeout is the timeout value controlling when to abort
The number of seconds to wait for data from a connection before terminating the read; net_read_timeout controls when the server times out while reading data from a client.

net_write_timeout:

The number of seconds to wait for a block to be written to a connection before aborting the write. When the server is writing to the client, net_write_timeout is the timeout value controlling when to abort.
How many seconds to wait to write a block to the connection before terminating the write; when the service is writing data to the client, net_write_timeout controls when to time out.

wait_timeout

The number of seconds the server waits for activity on a noninteractive connection before closing it.
The time it takes for a connection with no interaction to be closed by the server.

interactive_timeout :

The number of seconds the server waits for activity on an interactive connection before closing it.
The time it takes for a connection with no interaction to be closed by the server.

connect_timeout

The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake. The default value is 10 seconds.

The time to wait for a connection response

connect_timeout: takes effect during the connection acquisition phase (authentication)

interactive_timeout and wait_timeout: work during the connection idle phase (sleep)
net_read_timeout and net_write_timeout: take effect during the busy connection phase (query).

Acquiring a MySQL connection is the result of multiple handshakes. In addition to the matching verification of the username and password, there is also IP->HOST->DNS->IP verification. Any step may cause thread blocking due to network problems. To prevent threads from being wasted on unnecessary verification waits, connection requests that exceed connect_timeout will be rejected.

Even if there are no network problems, you cannot allow the client to occupy the connection all the time. MySQL actively disconnects clients that remain in sleep state for longer than wait_timeout (or interactive_timeout, depending on the client_interactive flag).

Even if the connection is not in sleep state, that is, the client is busy calculating or storing data, MySQL chooses to wait conditionally. During the data packet distribution process, the client may not have time to respond (sending, receiving, or processing the data packet too slowly). In order to ensure that the connection is not wasted in endless waiting, MySQL will also choose to actively disconnect the connection conditionally (net_read_timeout and net_write_timeout).

refer to:

http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html

The above is a detailed summary of MySQL and connection-related timeouts. If you have any questions, please leave a message or discuss in the community. Thank you for reading and I hope it can help you. Thank you for your support of this site!

You may also be interested in:
  • Difference between interactive_timeout and wait_timeout in MySQL
  • C3P0 connection pool + MySQL configuration and wait_timeout problem solution
  • A cluster problem solved by the MySQL slave_net_timeout parameter

<<:  How to use Antd's Form component in React to implement form functions

>>:  Explanation on the use and modification of Tomcat's default program publishing path

Recommend

Common errors and solutions for connecting Navicat to virtual machine MySQL

Question 1 solve Start the service: service mysql...

Script to quickly list all host names (computer names) in the LAN under Linux

Recently, I have a need to list all host names in...

Interpretation and usage of various React state managers

First of all, we need to know what a state manage...

A brief understanding of MySQL storage field type query efficiency

The search performance from fastest to slowest is...

Detailed explanation of html-webpack-plugin usage

Recently, I used html-webapck-plugin plug-in for ...

MySQL 5.7.17 Compressed Version Installation Notes

This article shares the installation steps of MyS...

Detailed tutorial on Tomcat installation and deployment in Windows 10

Table of contents 1 Java environment configuratio...

How to configure multiple projects with the same domain name in Nginx

There are two ways to configure multiple projects...

Detailed graphic explanation of how to clear the keep-alive cache

Table of contents Opening scene Direct rendering ...

How to implement a lucky wheel game in WeChat applet

I mainly introduce how to develop a lucky wheel g...

A possible bug when MySQL executes the sum function on the window function

When using MySql's window function to collect...

How to hide rar files in pictures

You can save this logo locally as a .rar file and...

The new version of Chrome browser settings allows cross-domain implementation

Preface Currently, the front-end solves cross-dom...

Vue+ElementUI implements paging function-mysql data

Table of contents 1. Problem 2. Solution 2.1 Pagi...