Error Code: 2013. Lost Connection to MySQL Server During Query

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

New versions of MySQL WorkBench have an option to change specific timeouts.

For me it was under Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600

Changed the value to 6000.

Also unchecked limit rows as putting a limit in every time I want to search the whole data set gets tiresome.

MySQL(Cursors/stored procedures): Error Code: 2013. Lost connection to MySQL server during query 6000.015 sec

The actual select/insert code looks straightforward and should not take that much time.

Do following:

  • Create the index outside the procedure. Indexes are created once whereas a procedure can be called many times
  • Do not serialize the queries when you do not need to. Use a join in a update instead of a cursor

SQL:

UPDATE telefon
JOIN personalstamm ON personalstamm.persnr = telefon.persnr
SET telefon.gueltig_bis = personalstamm.austritt
WHERE telefon.gueltig_bis is null

getting Error Code: 2013 Lost connection to MySQL server during query while running recursive stored procedure

The normalized way to store hierarchical data is to store a reference to the parent, not store a comma-separated list of the children.

idparent_id
1NULL
c11
c21
c31
c11c1
c12c1
c13c1
c21c2
c22c2

MySQL Stored Procedure fails with Error Code 2013 (Lost connection to MySQL server during query)

Firstly, you are serializing a query that you do not need to. The cursor with 143115 rows causes 1 select and 1 update for each row resulting 143115*2 + 1 = 286231 SQL operations. This will take so much time that your execution times out (error 2013).

Secondly, your cursor logic seems to be bit off. When the cursor loop ends (no more rows to handle), it will turn the exit_loop variable to true. Yet you are trying to make last update and turn the exit_loop back to false as if the cursor should continue.

You probably can do the same with single SQL operation where you have all the logic:

UPDATE mdl_edulevel2_log l
INNER JOIN mdl_enrollments e ON e.m_relateduserid = l.userid
AND ((l.timecreated >= e.m_timecreated)
AND (l.timecreated <= e.dm_timecreated OR e.dm_timecreated = 0)
)
SET enrollmentid = ifnull(e.enrollmentid, "0 - 0")
WHERE l.userid not in (0, 2, 3);


Related Topics



Leave a reply



Submit