我正在使用 pycharm 2017 和 SQL Server 2019,我的问题是我使用以下代码:
import mysql.connector
cnx = mysql.connector.connect(user='sa', password='pooria1376',
host='localhost',
database='pooriadb')
cnx.close()
我看到这个错误:
C:\Python34\python.exe C:/Users/LA/PycharmProjects/untitled/main
Traceback (most recent call last):
File "C:\Python34\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/LA/PycharmProjects/untitled/main", line 5, in <module>
database='pooriadb')
File "C:\Python34\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Python34\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection
self._socket.open_connection()
File "C:\Python34\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)
Process finished with exit code 1
我还禁用了防火墙,“sa”是 SQL Server 的默认用户名,我确定我的密码是真的(因为我使用此信息登录)。任何人都可以帮助我吗?