title: Windows Authentication with MySQLdb in Python
body: <p>Is there a way to connect to MySQL database with Windows Authentication in Python? It is enabled on MySQL server, I login into it with Microsoft MySQL Server Management Studio no problem. However, usual setup:</p>
  
  <pre><code>import MySQLdb
  db = MySQLdb.connect(host="sampleserver\\demo",
                        db="sample") 
  </code></pre>
  
  <p>doesnt seem to work. In fact, host is not even recognized. Our DBA didnt give me a endpoint aside from that host. It works for the Management Studio.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>As per suggestion in the answer, tried connecting with the connection string method with pyodbc library.</p>
  
  <pre><code>import pyodbc
  cnxn = pyodbc.connect("DRIVER={SQL Server};"
                        "SERVER=server_name\\demo;"
                        "DATABASE=sample;"
                        "UID=auth_windows")
  </code></pre>
  
  <p>Double backslash, I'm escaping the backsalsh in the server name</p>
  
  <p>Getting fairly long error message:</p>
  
  <pre><code>Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'auth_windows'. (18456) (SQLDriverConnect); 
  [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'auth_windows'. (18456)")
  </code></pre>
  
  <p>When I tried to add <code>IntegratedSecurity=yes</code>, I also get:</p>
  
  <pre><code>[01S00] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0)
  </code></pre>