title: Using a context manager with mysql connector python
body: <p>I'm moving my code across from an sqlite database to mysql and I'm having a problem with the context manager, getting the following attribute error.</p>
  
  <p>I've tried combinations of mydb.cursor() as cursor, mydb: etc...</p>
  
  <pre><code>
  
  mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="",
      database="database_name"
  
  cur = mydb.cursor()
  
  </code></pre>
  
  <pre><code>with mydb as cursor:
   AttributeError: __enter__
  </code></pre>