Why does mysql connector break ("Lost connection to MySQL server during query" error)

I also had to switch to PyMySQL. I am running pip 1.5.6, Python 2.7.8, and tried mysql-connector 2.0.1

I was able to run the query from within Sequel Pro with no problems, but my Python query would fail with the error described in the question after returning just a subset of results.

Switched to PyMySQL and things work as expected.

https://github.com/PyMySQL/PyMySQL

In the virtualenv:

pip install pymysql

In the code:

import pymysql

connection = pymysql.connect(user='x', passwd='x',
                                 host='x',
                                 database='x')

cursor = connection.cursor()

query = ("MYQUERY")

cursor.execute(query)

for item in cursor:
    print item

Definitely a bug in mysql-connector-python.


Try increasing your net_read_timeout (probably a default value of 30secs is too small in your scenario)

Ref:

net_read_timeout

and in general:

B.5.2.3 Lost connection to MySQL server


I encountered similar problems too. In my case it was solved by getting the cursor in this way:

cur = connection.cursor(buffered=True)

Tags:

Python

Mysql

Mamp