title: Why does mysql connector break ("Lost connection to MySQL server during query" error)
body: <p>When I run large queries (queries returning many rows), I get the  <code>Lost connection to MySQL server during query</code> error, and I cannot see what I do wrong. I use the "new" mysql driver from mysql.com (not the "old" MySQLdb), and the mysql version that is bundled with MAMP. Python 2.7. Table is not corrupted, <code>analyze table nrk2013b_tbl;</code> returns status ok. Here's an example that breaks:</p>
  
  <pre><code>#!/usr/bin/python2.7
  # coding: utf-8
  
  import sys
  import mysql.connector # version 2.0.1
  
  connection = mysql.connector.connect(
                      unix_socket="/Applications/MAMP/tmp/mysql/mysql.sock",
                       user="dbUsernam",
                        passwd="dbUserPassword",
                        db="nrk",
                        charset = "utf8",
                        use_unicode = True)
  cur = connection.cursor()
  cur.execute("USE nrk;")
  
  
  sql = """SELECT id FROM nrk2013b_tbl WHERE main_news_category = 'Sport'"""
  cur.execute(sql)
  rows = cur.fetchall()
  
  print rows
  
  sys.exit(0)
  </code></pre>
  
  <p>This results in the error I get most of the time:</p>
  
  <pre><code>Traceback (most recent call last):
    File "train_trainer_test.py", line 20, in &lt;module&gt;
      remaining_rows = cur.fetchall()
    File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 823, in fetchall
      (rows, eof) = self._connection.get_rows()
    File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 669, in get_rows
      rows = self._protocol.read_text_result(self._socket, count)
    File "/Library/Python/2.7/site-packages/mysql/connector/protocol.py", line 309, in read_text_result
      packet = sock.recv()
    File "/Library/Python/2.7/site-packages/mysql/connector/network.py", line 226, in recv_plain
      raise errors.InterfaceError(errno=2013)
  mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
  </code></pre>
  
  <p>Line 20 is the <code>rows = cur.fetchall()</code></p>
  
  <p>If I limit the query to result fewer result <code>SELECT id FROM nrk2013b_tbl WHERE main_news_category = 'Sport' LIMIT 10</code> all is well. But I do want to work with larger result sets. For some ad-hoc problem solving I have moved the limit and broken down the data I wanted into smaller batches, but this keeps popping up as a problem. </p>
  
  <p>In order to take connect-timeout, and max_allowed_packet, etc into account, I have this my.cnf-file: <code>File: /Applications/MAMP/conf/my.cnf</code> </p>
  
  <pre><code>[mysqld]
  max_allowed_packet = 64M
  wait_timeout = 28800
  interactive_timeout = 28800
  connect-timeout=31536000
  </code></pre>
  
  <p>This does not seem to make any difference (I'm not even sure if mysql recognises these settings). When I run queries from the terminal or from Sequel Pro, it works fine. It is only through the python mysql.connector I get these errors. </p>
  
  <p>Any ideas? </p>
  
  <p>PS: I've temporarily given this up, and changed to PyMySQL instead of of the Oracle mysql.connector. By changing to this, the problems seems to disappear (and I conclude for myself that the problem is in the oracle mysql connector). </p>
  
  <pre><code>import pymysql
  conn = pymysql.connect(
                      unix_socket="/Applications/MAMP/tmp/mysql/mysql.sock",
                       user="dbUsernam",
                        passwd="dbUserPassword",
                        db="nrk",
                        charset = "utf8",
                        use_unicode = True)
  conn.autocommit(True)
  cur = conn.cursor()
  </code></pre>