【发布时间】:2017-06-04 15:00:18
【问题描述】:
我无法通过 Python 远程连接到 mySQL 数据库。
我使用以下连接到 mySQL:
import mysql.connector
cnx = mysql.connector.connect(host='XXX.XXX.XXX.X',user='XXXX',password='XXXXXX',database='testdb')
但我收到以下错误:
2003: Can't connect to MySQL server on '%HOST%:3306' (10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)
服务器正在运行,当我在计算机上运行相同的代码时,我使用 'localhost' 运行服务器
导入 mysql.connector
cnx =
mysql.connector.connect(host='localhost',user='XXXX',password='XXXXXX',database='testdb')
它有效,我可以修改数据库中的数据。我正在尝试从另一台计算机远程连接它。
我尝试过使用GRANT ALL ON *.* TO User@Host IDENTIFIED BY 'password';,但没有结果。我检查了我的防火墙并允许通过默认使用的端口 3306 进行所有传入和传出连接。
我是 mySQL 的新手,真的不知道该怎么做。我什至不知道我是否使用了正确的主机名 :') 我使用了运行服务器的计算机的 IP 地址,我认为这是正确的。
【问题讨论】: