0

I’m running a query on a large MySQL table and consistently get Error Code: 2013 – Lost connection to MySQL server during query.

Query example:

WITH duplicates AS (
 SELECT
 event_time,
 event_type,
 product_id,
 category_id,
 category_code,
 brand,
 price,
 user_id,
 user_session,
 COUNT(*) AS count
 FROM temp_feb_2020
 GROUP BY 1,2,3,4,5,6,7,8,9
 HAVING count > 1
)
SELECT SUM(count) 
FROM duplicates;

Error:

Error Code: 2013. Lost connection to MySQL server during query 30.016 sec

Context:

Table has ~4 million rows (9 columns).

Full dataset is ~20 million rows.

Cleaning/merging requires CTEs and window functions, but they time out.

What I’ve tried:

Edited my.ini file:

[mysqld]
net_read_timeout = 3600
net_write_timeout = 3600
max_allowed_packet = 128M

Tried session settings:

SET SESSION interactive_timeout = 3600;
SET SESSION wait_timeout = 3600;
SET SESSION net_read_timeout = 3600;
SET SESSION net_write_timeout = 3600;

I've also tried to to adjust the max_execution_time

set global max_execution_time = 400000;
set session max_execution_time = 400000;

Restarted MySQL after changes.

Question:
What is the correct way to increase MySQL’s server timeout so that long-running queries (30–60s+) can complete without Error 2013?

J.D.
41k12 gold badges63 silver badges144 bronze badges
asked Aug 29 at 19:48
1
  • 1
    It's not a MySQL Server timeout. The MySQL Workbench (the GUI client) has its own client-side timeout. You already asked this question on Stack Overflow, and you were directed to this answer showing how to change the client timeout in MySQL Workbench: stackoverflow.com/questions/10563619/… Commented Aug 30 at 14:45

2 Answers 2

1

I do not know what in particular fixed it, but i will walk through everything i did.

I went to server > status and system variables > system variables > scrolled to other/x > located mysqlx_connection_timeout and increased it. This is where you should be

Note: You have to triple click on the value to edit it.

This is the code now:

with duplicates as 
(select
 event_time,
 event_type,
 product_id,
 category_id,
 category_code,
 brand,
 price,
 user_id,
 user_session,
 count(*) as count from temp_feb_2020 group by 1,2,3,4,5,6,7,8,9 having count > 1
 )
 select sum(count) from duplicates;

Response:

1 row(s) returned 155.469 sec / 0.000 sec.

The reason for my confusion:

After I changed the mysqlx_connection_timeout and the query worked, I tested to see if that was the issue by changing it back to 30, but the query still worked. I had tried the query just before making the change and it failed that’s why I’m not entirely sure what actually fixed the problem.

answered Aug 30 at 9:27
4
  • BTW, Here you say thanks by upvoting 🙂 Commented Aug 30 at 10:20
  • i need to gain 15 reputation points first, i have just 11 🫠. yesterday was my first time ever using this platform. ill give you an upvote once i can. Commented Aug 30 at 12:16
  • The mysqlx variables are for the MySQL X Plugin, which I don't think you're using if you're using MySQL Workbench (or almost any other client). Commented Aug 30 at 14:51
  • like i said, i am not sure what caused it to work. I changed that and it just worked. Commented Aug 31 at 14:14
0

Try this to prove if its timeout. I dont think it is.

max_execution_time = 0

So,

  • Increase all table size and buffer parameters.
  • Increase buffer and timeouts on your client
  • See if you can add indexes to improve the speed of the query
answered Aug 30 at 0:30
1
  • I tried that, but it didn't have any effect. Thanks for the suggestion and the corrections. Commented Aug 30 at 5:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.