如何克服 sql 与 python 的连接错误?
How do I overcome this sql connectivity error with python?
我无法使用 python
连接到 MySQL
服务器,它给出了
错误
MySQLdb._exceptions.OperationalError: (1130, "Host 'LAPTOP-0HDEGFV9' is not allowed to connect to this MySQL server")
我使用的代码:
import MySQLdb
db = MySQLdb.connect(host="LAPTOP-0HDEGFV9", # your host, usually localhost
user="root", # your username
passwd="abcd13de",
db="testing") # name of the data base
cur = db.cursor()
cur.execute("SELECT * Employee")
for row in cur.fetchall():
print(row[0])
db.close()
这是授权问题,不是连接问题。 db 运行 是本地的吗?如果不是,请与托管它的管理员确认。如果是这样,请尝试将主机参数更改为 127.0.0.1
?
如所述here管理员可以通过运行:
获取主机名
select @@hostname;
show variables where Variable_name like '%host%';
如果连接超时,您可以尝试设置 connect_timeout
kwarg,但默认情况下已经 None
。
我无法使用 python
连接到 MySQL
服务器,它给出了
MySQLdb._exceptions.OperationalError: (1130, "Host 'LAPTOP-0HDEGFV9' is not allowed to connect to this MySQL server")
我使用的代码:
import MySQLdb
db = MySQLdb.connect(host="LAPTOP-0HDEGFV9", # your host, usually localhost
user="root", # your username
passwd="abcd13de",
db="testing") # name of the data base
cur = db.cursor()
cur.execute("SELECT * Employee")
for row in cur.fetchall():
print(row[0])
db.close()
这是授权问题,不是连接问题。 db 运行 是本地的吗?如果不是,请与托管它的管理员确认。如果是这样,请尝试将主机参数更改为 127.0.0.1
?
如所述here管理员可以通过运行:
获取主机名select @@hostname;
show variables where Variable_name like '%host%';
如果连接超时,您可以尝试设置 connect_timeout
kwarg,但默认情况下已经 None
。