gpt4 book ai didi

python连接mySql错误-ConnectionRefusedError : [WinError 10061]

转载 作者:行者123 更新时间:2023-11-28 23:38:23 25 4
gpt4 key购买 nike

我尝试使用 python 连接 mySql 服务器,这是我的代码(当然我将数据库详细信息更改为假的):

    import pymysql
connMySql= pymysql.connect (
host = "blahblah.ipagemysql.com",
user = "blah",
passwd = "1234",
db = "db_book")

cur = connMySql.cursor()
print ("writing to db")
connMySql.commit()

此程序给出以下错误:

Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 836, in connect
(self.host, self.port), self.connect_timeout)
File "C:\Python34\lib\socket.py", line 509, in create_connection
raise err
File "C:\Python34\lib\socket.py", line 500, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/proj/projpy.py", line 432, in <module>
db = "db_book")
File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\__init__.py", line 88, in Connect
return Connection(*args, **kwargs)
File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 657, in __init__
self.connect()
File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pymysql\connections.py", line 882, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'blahblah.ipagemysql.com' ([WinError 10061] \u200f\u200f)")

知道怎么解决吗?

最佳答案

在我包含您的服务器可能也需要的“端口”参数之前,我遇到了同样的错误?

connection = pymysql.connect(host = host,
user = user,
db = db,
password = password,
port = port)

关于python连接mySql错误-ConnectionRefusedError : [WinError 10061],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35139788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com