Question: I am doing bulk inserting and getting error as `Mysql2::Error: Lost connection to MySQL server during query:`

I searched for this error on the Internet and most of the blogs/articles asking to increase `net_read_timeout` value.

I searched on the Internet about `net_read_timeout` but not getting any article/blog which describes it in easy to understandable language.
On MySQL website net\_read\_timeout is describe as `"The number of seconds to wait for more data from a connection before aborting the read"`. I am totally confused with this statement and not getting it.

I also want to know about net\_write\_timeout and wait\_timeout variable.

Answer: 
I understood about wait\_timeout settings. mysql default wait\_timeout is 28800 seconds which 8 hours. now to understand how wait\_timeout works execute following sql statement.

set wait\_timeout = 10;

After executing above statement if mysql server has not received any sql statement withing 10 seconds then it will automatically close the connection.

To test it wait for 10 seconds and then execute any sql query it will give you error like "mysql closed connection during query execution"

will update my answer for net\_read\_timeout and net\_write\_timeout shortly.
This is happening when you are using the non-buffering connection to the mysql database, and after executing your query, you are not consuming the data.
client python connect with non-buffering SSDictCursor

```
connection = pymysql.connect(host='localhost',
                             user='xxxx',
                             password='xxxx',
                             db='employees',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.SSDictCursor)
sql = " select * from employees"
cursor = connection.cursor()
cursor.execute(sql)
cursor.fetchone()

```

doing nothing and your connection will be timed out
or
if not fetching all data within 60 seconds(net\_write\_timeout), your connection will be aborted.  

quote from doc:
When the server is writing to the client, net\_write\_timeout is the timeout value controlling when to abort

2019-08-14T15:20:26.465498Z 28440 Query select \* from employees

2019-08-14T15:21:26.584634Z 28440 [Note] Aborted connection 28440 to db: 'employees' user: 'xxxx' host: 'localhost' (Got timeout writing communication packets)