我正在尝试从Windows 10连接远程(托管在dreamhost上) MySQL数据库。
我安装了32位MySQL ODBC驱动程序的最新版本(我正在运行32位python),并运行以下代码:
connection_string = (
r'DRIVER=MySQL ODBC 8.0 ANSI Driver;'
r'SERVER=https://mysql.mysite.com;'
r'DATABASE=dbname;'
r'UID=userid;'
r'PWD=password;'
r'charset=utf8mb4;'
)
cnxn = pyodbc.connect(connection_string)
cursor = cnxn.cursor()显然,使用正确的服务器、数据库名、userID和密码。
我可以使用这些信息和凭据从mysql工作台访问它,但是当我运行上面的代码时,我会得到以下消息:
The procedure entry point OPENSSL_sk_new_reserve could not be
located in the dynamic link library c:\Program Files (x86)
MySQL\Connector ODBC 8.0\libssl-1_1.dll.当我单击“确定”时,我会在控制台中得到以下消息:
Traceback (most recent call last):
File "C:\Users\pasto\OneDrive\Documents\Python\work.py", line 129, in <module>
print(get_mysql_data())
File "C:\Users\pasto\OneDrive\Documents\Python\work.py", line 109, in get_mysql_data
cnxn = pyodbc.connect(connection_string)
pyodbc.InterfaceError: ('IM003', '[IM003] Specified driver could not be loaded due to system error 127: The specified procedure could not be found. (MySQL ODBC 8.0 ANSI Driver, C:\\Program Files (x86)\\MySQL\\Connector ODBC 8.0\\myodbc8a.dll). (160) (SQLDriverConnect)')我尝试过的其他事情:
Google我所发现的只是关于蟒蛇的东西,很明显,它也有这个问题。
重命名libssl_1-1.dll库,然后错误代码更改为
pyodbc.InterfaceError: ('IM003', '[IM003] Specified driver could not be loaded
due to system error 126: The specified module could not be found.
(MySQL ODBC 8.0 ANSI Driver, C:\\Program Files (x86)\\MySQL\\Connector ODBC
8.0\\myodbc8a.dll). (160) (SQLDriverConnect)')然后mysql-connector,尝试了安装(通过pip)
import mysql.connector
mydb = mysql.connector.connect(
host="https://mysql.mysite.com",
user="username",
password="password"
)但那只会让我
File "C:\Program Files (x86)\Python37-32\lib\site-packages\mysql\
connector\network.py", line 600, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL
server on 'https://mysql.fairplainpc.com:3306' (11001 getaddrinfo failed)我已经做了几个小时了,我几乎放弃了,使用请求库来下载一个PHP页面,然后用我想要的数据进行解析,但是我真的更愿意这样做。
发布于 2020-07-21 16:45:35
发布于 2020-07-21 16:46:30
用您的数据尝试这个connection_string:
connection_string = (
'DRIVER={MySQL ODBC 3.51 Driver};'
'SERVER=https://mysql.mysite.com;'
'DATABASE=dbname;'
'USER=userid;'
'PASSWORD=password;'
)如果不自己运行mysql服务器,则可能必须将ip地址分配给数据库用户,或者将ip添加到排除之外。
例如Hostpoint (瑞士):

https://stackoverflow.com/questions/63015192
复制相似问题