所以我目前正在使用MySQL建立数据库,由于某种原因它无法正常工作。
这是我的代码:
import mysql.connector
mydb = mysql.connector.connect(host='localhost', user='name', passwd='12345')
我搜索了一下,发现我应该尝试将“ localhost”更改为“ 127.0.0.1”,但是我遇到了同样的错误。 这是我得到的错误:
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python37/python.exe c:/Users/name/Desktop/database/main.py
Traceback (most recent call last):
File "C:\Users\name\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\network.py", line 509, in open_connection
self.sock.connect(sockaddr)
ConnectionRefusedError: [WinError 10061] Det gick inte att göra en anslutning eftersom måldatorn aktivt nekade det
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/name/Desktop/database/main.py", line 3, in <module>
mydb = mysql.connector.connect(host='localhost', user='name', passwd='12345')
File "C:\Users\name\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\name\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Users\name\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Users\name\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection
self._socket.open_connection()
File "C:\Users\name\AppData\Local\Programs\Python\Python37\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 Det gick inte att göra en anslutning eftersom måldatorn aktivt nekade det)
PS C:\Users\name>
感谢您的帮助!