Content migrations usually involve running complex MySQL queries that take a long time to complete. I’ve found the WordPress wp_postmeta table especially troublesome because a site with tens of thousands of posts can easily have several hundred thousand postmeta entries.
If your query ends up taking more than a few minutes to complete, you may encounter the following error:
Error Code: 2013. Lost connection to MySQL server during query
This happens because the connection between your MySQL client and database server times out. Essentially, it took too long for the query to return data so the connection gets dropped. The MySQL documentation suggests increasing the
connect_timeout values on the server. If this doesn’t solve the problem, you may need to increase your MySQL client’s timeout values.
You can edit the SQL Editor preferences in MySQL Workbench:
- In the application menu, select Edit > Preferences > SQL Editor.
- Look for the MySQL Session section and increase the DBMS connection read time out value.
- Save the settings, quite MySQL Workbench and reopen the connection.
How to edit Navicat preferences:
- Control-click on a connection item and select Connection Properties > Edit Connection.
- Select the Advanced tab and increase the Socket Timeout value.
On the command line, use the
If you’re running a query from a Python script, use the connection argument:
con.query('SET GLOBAL connect_timeout=6000')