此代码工作正常:
import MySQLdb
db = MySQLdb.connect("localhost", "root", "","bullsorbit")
cursor = db.cursor()
cursor.execute("Select * from table where conditions'")
numrows = int(cursor.rowcount)
print 'Total number of Pages : %d ' % numrows
但是如果我给我的IP地址
db = MySQLdb.connect("192.168.*.*", "root", "","bullsorbit")
它会导致这个错误
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'ip address' (111)")
代码2003是一个standard MySQL client error:
我猜您的用户不允许使用iP地址连接到MySQL服务器。如果尝试使用MySQL命令行客户机进行连接,会发生什么情况?
而不是:
db = MySQLdb.connect("192.168..", "root", "","bullsorbit")
尝试:
db = MySQLdb.connect(user="root", host="192.168..", db="bullsorbit")
密码将默认为空字符串,并尝试常用的标识方法。主机在默认端口上也将默认为localhost。
使用本地主机,您可以通过环回接口进行连接。
使用ip地址连接-从外部连接。
如果服务器只允许本地(环回)连接 你的ip地址连接失败。(安全!)
看看你的mysql配置,也许只允许本地连接。
跳过网络是否关闭(在mysql配置中)?
相关问题 更多 >
编程相关推荐