title: Python mysql.connector timeout
body: <p>Here's a simple connection to a MySQL database using the mysql.connector module.</p>
  
  <pre><code>db = mysql.connector.connect(
      host=DB_SERVER,
      port=DB_PORT,
      user=DB_UNAME,
      passwd=DB_PASSWORD,
      db=DB_NAME)
  db.connect()
  mysqlCursor.execute(query)
  </code></pre>
  
  <p>I want to control two different timeouts. First, I want it to spend no longer than five seconds on the .connect() function. I've got that figured out.
  Second, I want it to spend no longer than one second on the .execute() function. How can I do that?</p>
  
  <p>I'm the database administrator, so I can do something on that end if I need to. I'd prefer only to change the timeout for one particular MySQL user, though, and not for everyone, which is why I'm starting from the Python side.</p>
  
  <p>Here's what I've found so far:</p>
  
  <p>The <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html" rel="noreferrer">documentation</a> for mysql.connecter lists several timeout parameters. Connect-timeout will set the timeout for the initial connection, but as far as I can tell, it won't set a query timeout. Interactive-timeout will cause it to timeout if there's no activity, but I don't think that means it will timeout if the query takes too long to execute.</p>
  
  <p><strong>connect-timeout=seconds</strong>
  Connect timeout in seconds. On Linux this timeout is also used for waiting for the first answer from the server.
  (timeout has been replaced by connect-timeout, but timeout is still supported in MySQL 5.0 for backward compatibility.)</p>
  
  <p><strong>interactive-timeout=seconds</strong>
  Permit seconds of inactivity before closing the connection. The client's session wait_timeout variable is set to the value of the session interactive_timeout variable.</p>