_mysql_exceptions.OperationalError: (2013, ‘Lost connection to MySQL server during query’)

Because mysql has a default connect_timeout time, once it exceeds, it will automatically close the connection.

You can try the following two ways:

  • The connect_timeout time is specified when creating a connection, and the setting is longer.
  • Every time you operate the database, a connection is established and closed after the operation. In the code, close the cursor in time and close the connection.

solve

Enter the command in the New Query windowshow global variables like "%timeout%";

use commandSET GLOBAL connect_timeout = 24*3600;


1. The MySQL server is really gone

We can check if the server is indeed gone by checking the server uptime (uptime) and the server's error log.

Check MySQL's uptime (uptime):show global status like "uptime";

 

Query the storage location of the error log, then open the error log, and check whether the server is down based on the log records.

Query the storage location of the error log:show variables like "%error";

 

If the MySQL server does disappear, is it down or crashed, MySQL's error log will provide the answer. Normally the MySQL daemon (mysqld) will be restarted by the mysqld_safe wrapper process.

 

### 2. Connection timeout

View various connection times:show global variables like "%timeout";

 

These values are relatively MySQL defaults, but if your timeout is short, you may get this error, like:

 

3. Your SQL statement was killed

Some systems will actively kill SQL statements that are running too long, we can check if this might happen by looking at the number of kill statements that have been executed.

Check that the mysql request connection process is actively killed:show global  status like "com_kill";

 

4. Your SQL statement is too large

Slightly harder to test and verify, but MySQL uses the largest packet station site for communication between server and client. If the statement contains large fields, it may be aborted due to the size of the SQL statement.

We can check the maximum allowed packet size through the statement:show global variables like "max_allowed_packet";   (1024*1024*5=5242880)

 

If the value is relatively small, you can set a larger value:set global max_allowed_packet=1024*1024*16; If the modification is not big enough, you can continue to increase it.

 

Note: The size set via the command line is only valid for this time and will return to the original value after a reboot. The parameters can be set permanently by modifying the configuration file (my.ini).

Related articles

MySQL Log Files - Error Log and Slow Query Log

Experimental environment: MySQL Community Server (GPL) 5.7.17, Ubuntu 16.04 MySQL Log File Classification Official documentation: https://dev.mysql.com/doc/refman/5.7/en/server-logs.html Log files record various types of activities affecting MySQL data

Python Errors and Exceptions

The keyword for exception handling in python is different from that in c#. In python, try and except are used to handle exceptions, such as the following: 2. raise excepption

Spring 406 error

The web page appears 406 generally for the following two situations: 1.Missing jar package 2.If the URL of the access url has a suffix ending in .html, the server cannot respond to the json data. Because springMVC will mistakenly think that the request

squid Deployment

YUM installation yum install squid -y yum install httpd-tools -y Compile and install cd squid* ./configure \ --prefix=/usr \ --exec-prefix=/usr \ --includedir=/usr/include \ --datadir=/usr/share \ --libdir=/usr/lib64 \ --libexecdir=/usr/lib64/squid \ --lo

webservice example

What is webservice: WebService is a remote invocation technology across programming languages and operating system platforms. The so-called cross programming language and cross operating platform means that the server program is written in java, and the

Native jdbc example with spring JDBC example

Native jdbc integration with spring Introduction to JDBC The JDBC API allows users to access any form of tabular data, especially data stored in relational databases. Implementation process: Connect to a data source, such as a database. Pass query

Deploying Nginx

How to install PostgreSQL Linux downloads (Red Hat family) Tip: The current version is Version 10.3 surroundings [root@h210 ~]# hostnamectl Static hostname: h210 Icon name: computer-vm

Install OpenVPN

OpenVPN is an open source VPN (Virtual private network) software OpenVPN is a full-featured SSL VPN which implements OSI layer 2 or 3 secure network extension using the industry standard SSL/TLS protocol, supports flexible client authentication methods ba

mysql binlog transaction logs

binlog is binary log, binary log file, this file records all mysql dml operations. Through the binlog log, we can do data recovery, master-resident replication and master-slave replication, etc. Developers may not pay much attention to binlog

istio Deployment

1.istio Deployment Download address: https://github.com/istio/istio/releases Network disk link: https://pan.baidu.com/s/1L4CK2icK6teT5Ef4eiJwKw Password: i16u Resource allocation: ​master 2U2G ​node 2U8G curl -L https://git.io/getLatestIstio | ISTIO_