python mysql连接问题

2024-10-01 22:36:48 发布

您现在位置:Python中文网/ 问答频道 /正文

此代码工作正常:

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)")

Tags: 代码fromimportlocalhostexecutedbconnecttable
3条回答

代码2003是一个standard MySQL client error

Error: 2003 (CR_CONN_HOST_ERROR) Message: Can't connect to MySQL server on '%s' (%d)

我猜您的用户不允许使用iP地址连接到MySQL服务器。如果尝试使用MySQL命令行客户机进行连接,会发生什么情况?

$ mysql --host=192.168.1.1 -u root bullsorbit

而不是:

db = MySQLdb.connect("192.168..", "root", "","bullsorbit")

尝试:

db = MySQLdb.connect(user="root", host="192.168..", db="bullsorbit")

密码将默认为空字符串,并尝试常用的标识方法。主机在默认端口上也将默认为localhost。

使用本地主机,您可以通过环回接口进行连接。

使用ip地址连接-从外部连接。

如果服务器只允许本地(环回)连接 你的ip地址连接失败。(安全!)

看看你的mysql配置,也许只允许本地连接。

跳过网络是否关闭(在mysql配置中)?

#skip-networking

相关问题 更多 >

    热门问题