使用python 3.3.1连接到mysql数据库的密码错误

bhu*_*dya 5 python mysql python-3.x

我是python的新手,试图通过编写连接到我们的mysql数据库并做一些事情的服务器脚本来学习一些知识。我有python 3.3.1和mysql 5.0.96(社区)。我安装了mysql连接器/ python,并尝试使用mysql开发人员站点上的示例代码进行基本连接。这是我简单的python脚本:

#!/usr/local/bin/python3


import sys
import mysql.connector

db_config = {
    'user': 'joebloggs',
    'password': 'cleartext_passwd',
    'host': '127.0.0.1',
    'database': 'mydb'
}
cnx = mysql.connector.connect(**db_config)
cursor = cnx.cursor()
query = ('select usable_name, user_id from user')
cursor.execute(query)
for (usable_name, user_id) in cursor:
    print("{} is the usable name of {d}".format(usable_name, user_id))
cursor.close()
cnx.close()
Run Code Online (Sandbox Code Playgroud)

但我在连接数据库时遇到错误

"Authentication with old (insecure) passwords "\
mysql.connector.errors.NotSupportedError: Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manual
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?任何帮助表示赞赏

Mar*_*c B 3

MySQL 支持两种密码加密方案,您使用的是旧版本。新客户拒绝使用它们,因为它们非常容易破解。

您需要将密码更新为新样式:http://dev.mysql.com/doc/refman/4.1/en/old-client.html

  • 感谢您的回复。我找到了答案,但它有点晦涩(至少对我来说!)。在 stackoverflow 上发帖之前,我做的第一件事就是更新 mysql 用户表中的密码以使用新样式的密码。python 脚本仍然无法工作。然后在检查您的链接后,我在 phpMyAdmin 中检查了该用户的权限,并且如我所料,它已设置为使用新密码。嗯嗯。但最终我要做的是“刷新权限”以使用新信息更新 mysqld。瞧,蟒蛇很高兴!我也很高兴!谢谢! (2认同)