pyodbc + MySQL + Windows: Data source name not found and no default driver specified

后端 未结 4 703
甜味超标
甜味超标 2020-12-15 10:30

I am trying to connect to MySQL 5.6 on a Windows Server 2008 R2 localhost with pyodbc. I used the full installation for the MySQL instance on the localhost, including the OD

4条回答
  •  无人及你
    2020-12-15 11:34

    I was having a similar issue. I am using windows 8, and mysql.

    The way I solved the problem was by going into my

    control panel>Systems and Security>Administrative Tools.>ODBC Data Sources

    Either the 32 bit or 64 bit version depending on your computer.

    Then you click on the System DNS file. If you do not see any MySQL driver you have to click ADD. It brings up a list, from that list select the MySQL driver.

    For me it was MySQL ODBC 5.3 ANSI(they have a unicode driver also). Click finish. Once you do that then you have to change your connection line in your code to the corresponding Driver that you just filled out.

    Ex:

    def create_mysql_conn():
    
     return pyodbc.connect(r'Driver={MySQL ODBC 5.3 ANSI Driver};Server=MSSQLSRV;Database=ecomm;Trusted_Connection=yes;')
    

    This should work, or at least it solved my connection issue because I was getting all sorts of different errors with everything I tried. This was what solved the issue for me.

提交回复
热议问题