以下是我的代码的相关部分:
try:
if self.pass_entry.get():
self.connection = pymysql.connect(
host=self.host_entry.get(),
user=self.user_entry.get(),
password=self.pass_entry.get(),
db=self.db_entry.get(),
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor
)
else:
self.connection = pymysql.connect(
host=self.host_entry.get(),
user=self.user_entry.get(),
db=self.db_entry.get(),
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor
)
except Exception as e:
self.console.insert(tk.END, "Error: {err}\n".format(err=str(e)))下面是错误:
Connecting to 127.0.0.1...
Error: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")“超级用户”上没有密码,PyMySQL假设它有一个密码。不使用密码如何连接?(我曾尝试在密码字段/字符串为空时省略密码选项,但PyMySQL不会将其考虑在内)。
发布于 2018-11-14 20:39:23
当数据库没有密码时,需要将"“作为密码传递给函数。
在你的其他应用中试试这个:
else:
self.connection = pymysql.connect(
host=self.host_entry.get(),
user=self.user_entry.get(),
password="",
db=self.db_entry.get(),
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor
)发布于 2018-11-14 21:25:31
我在使用mysql.connector库时也遇到了同样的问题。只需在root用户之外创建一个新的连接用户即可解决此问题。
在谷歌搜索了一段时间后,似乎访问root可能是问题所在,但在找到上述解决方案后,我放弃了对它的进一步研究。用户在MySQL中的设置与root@localhost相同。
def mySQLcnx(someVariable):
dbCnx = mysql.connector.connect(host="localhost", user="pythonCnx", database="someDatabase")
dbCnxCursor = dbCnx.cursor()
dbCnxCursor.execute(someStatement)
DbQueryResults = dbCnxCursor.fetchall()https://stackoverflow.com/questions/35881075
复制相似问题