gpt4 book ai didi

python - MySQL连接器无法正常工作并给出错误

转载 作者:行者123 更新时间:2023-11-29 07:16:46 26 4
gpt4 key购买 nike

我试图使用sql connector for python,使用以下代码:

import mysql.connector as mc


mydb = mc.connect(
host="localhost",
user="*****************",# could not include them, but the user and pass are correct
passwd='***************'
)
print(mydb)

但我无法连接到mysql,并出现以下错误:
Traceback (most recent call last):
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\network.py", line 509,
in open_connection
self.sock.connect(sockaddr)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine
actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/m.m/PycharmProjects/untitled9/f.py", line 7, in <module>
passwd='LQ,$5t^Rx6uS/nq'
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\__init__.py", line 179,
in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\connection.py", line 95,
in __init__
self.connect(**kwargs)
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\abstracts.py", line 716,
in connect
self._open_connection()
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\connection.py", line
206, in _open_connection
self._socket.open_connection()
File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\mysql\connector\network.py", line 512,
in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306'
(10061 No connection could be made because the target machine actively refused it)

如果有帮助。。。
我现在的位置是伊朗,所以我想问,这个问题是否碰巧与伊朗IP的限制有关?如果不是,那么这个错误是为了什么?
注意:my sql和sql connector模块安装正确,我已经创建了一个oracle帐户,没有问题,我已经在我的机器上安装了mysql connector for python。

最佳答案

这个问题可能发生在你身上,根据反对伊朗ip的限制,如果你希望这个问题不再发生,使用一个有效的VPN,你的问题将得到解决,即使你想直接从他们的网站下载数据库,你不必带着伊朗ip。

关于python - MySQL连接器无法正常工作并给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58842580/

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