2003年,"无法在' 192.168.1.xxx'上连接到MySQL服务器(10060)

时间:2015-11-26 17:28:27

标签: python mysql network-programming centos mariadb

我刚刚在服务器上安装了新的CentOS操作系统并恢复了所有数据库。 我试图使用Python脚本从Windows远程获取数据。 它给我带来了这个错误

PS C:\Python27\practice> python .\server_test_script.py
Traceback (most recent call last):
File ".\server_test_script.py", line 9, in <module>
db="transactions") # name of the data base
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on   '192.168.1.XXX' (10060)")

我已经使用bind-address = 0.0.0.0更改了我的/etc/my.cnf文件。还有一件事,当我使用yum命令下载mysql时,它安装了mariadb服务器。这是问题,但我不认为,因为两者都使用相同的包提供相同的服务。我已经创建了自己作为具有所有权限的用户,但它仍然没有工作。

这是我的Python脚本

import MySQLdb 
con = MySQLdb.connect(host="192.168.1.xxx", # your host, usually localhost
user="shubham", # your username
passwd="xxxxx", # your password
db="transactions") # name of the data base
cur = con.cursor()
def getTransactioncount():
    cur.execute("select count(tid) from transaction")
    row=cur.fetchall()
    count=row[0][0]
    return count

print getTransactioncount()

任何人都可以帮我找到我做错的地方 谢谢

1 个答案:

答案 0 :(得分:1)

检查从客户端到服务器的网络连接 - 很可能是问题所在。另请参阅Cannot connect to remote MySQL with VB6 (10060)http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html