Error Code 2013 Lost Connection to MySQL Server During Query — SQL Technical Interview Questions & Answers

Error Code 2013 Lost Connection to MySQL Server During Query

Error Code 2013 Lost Connection to MySQL Server During Query

  • Error Code 2013 Lost Connection to MySQL Server During Query is a MySQL error/mode, not a query type. Read the message: 1064 = syntax (look at the caret). 2006/2013 = connection dropped (timeout, packet, server restart). 1045 = access denied. 1062 = duplicate key.
  • Safe updates: Workbench blocks UPDATE/DELETE without a key. Either add WHERE pk = … or (lab only) SET SQL_SAFE_UPDATES=0. Don’t turn it off as a lifestyle.
  • Too many connections: close unused clients, raise max_connections only with care. ‘Server has gone away’: wait_timeout / max_allowed_packet / actually crashed server.
  • Trap: googling the code without reading the SQL line MySQL pointed at.

Technical Interview Tip: Name the error code, what it means, one fix.

Code Examples for Error Code 2013 Lost Connection to MySQL Server During Query

Error Code 2013 Lost Connection to MySQL Server During Query — sample query

CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT, dept TEXT, salary INTEGER);
INSERT INTO employees VALUES
  (1, 'Asha', 'Eng', 70000),
  (2, 'Ravi', 'Eng', 65000),
  (3, 'Neha', 'HR', 50000);
SELECT name, salary FROM employees WHERE dept = 'Eng' ORDER BY salary DESC;

Error Code 2013 Lost Connection to MySQL Server During Query — sELECT projects columns; WHERE filters; ORDER BY sorts.

How to Explain Error Code 2013 Lost Connection to MySQL Server During Query to an Interviewer

What is 1064?

Syntax error Look at the query near the marker