Problems restoring connection to MySQL server after <2013: Lost connection to MySQL server during query>

Asked by Thomas Karl Pietrowski on 2013-01-02

After experimenting with this python module I noticed that I can't query my table on my NAS over the internet.
It fetches just 200 rows and throws

2013: Lost connection to MySQL server during query

So I decided to make a workaround for that to recover the connection e.g. via .reconnect(), but this didn't work and I browsed the code and made a manual reconnect via disconnect() and connect().

So, the result was this traceback:
   File "/home/thopiekar/Projekte/eclipse/OBDX_LOOKUP_mobile/src/database.py", line 178, in reconnect_remote
     self.remote_connection.connect()
   File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 326, in connect
     self._post_connection()
   File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 305, in _post_connection
     self.set_charset_collation(charset=self._charset_id)
   File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 828, in set_charset_collation
     charset_name, collation_name))
   File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 1105, in _execute_query
     raise errors.InternalError("Unread result found.")
 mysql.connector.errors.InternalError: Unread result found.

After that I browsed the code for functions which might [Cursor].reset() or whatever to fix that problem, but nothing helped..

Could you give me a hint to fix that? It would be great!

(using Ubuntu Raring + latest mysql connector for python using my build at https://launchpad.net/~thopiekar/+archive/raring-dev/+packages)

Question information

Language:
English Edit question
Status:
Solved
For:
MySQL Connector/Python Edit question
Assignee:
No assignee Edit question
Solved by:
Geert JM Vanderkelen
Solved:
2013-01-03
Last query:
2013-01-03
Last reply:
2013-01-03

You can not tell MySQL to forget about a result set. You need to either:
1) Fetch the result after the query,
2) use Buffered cursor so the result is fetch right away (might be best with small results),
3) or you can disconnect (and reconnect) like you mentioned.

The 'Unread result found' should be handled by the application and make sure the results are read before executing any new statement.

Mentioning 'latest' is not specific enough. The latest at the time of writing and the time the question was asked is v1.0.8, which can be downloaded from the dev.mysql.com website. (Launchpad might lag behind when syncing.)

Well, I'm doing a disconnect() before connect() and it still happens.

In addition I tried to to a .fetch*() after [here: .fetchall() ], to get it work, but when doing this I get:
> No result set to fetch from.

I'll test now the last option you mentioned using a buffered cursor, even if it is a big table.

By the way: Where is the latest code hosted? GitHub?

If you can reproduce it with a (smaller) test case, please open a bug report on bugs.mysql.com. It looks a bit odd..

(We push to Launchpad after release, but it can lag a bit.)

Well, this problem seems to be fixed in the latest (1.0.8) version which can be found on dev.mysql.com.

Additionally: Could you sync the code with trunk at launchpad? I would like to make a updated package for it.

Thanks Geert JM Vanderkelen, that solved my question.