MySQL错误 - 您必须设置密码/密码哈希应为41位十六进制数字。

7

大家好,这可能只是一个简单的修复,但我似乎无法让它工作...

我正在尝试设置一个MySQL数据库(在RHEL上),但出现以下错误:

mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('new_pass');
ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number
mysql> SELECT PASSWORD('new_pass');
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

我尝试了所有可能的命令/查询,但无法绕过这两个错误消息。也许我的权限有问题?有什么想法吗?谢谢!


2
你有没有考虑查看 文档 来获取正确语法? - Ken White
1
在设置密码之前运行此命令:SET old_passwords = 0; - Mihai
2个回答

11
如果你想更改mysql密码,你应该使用以下命令代码:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('New_Password');

这种方法对我有效。 - Fabrizio Valencia

7

使用以下命令:SET old_passwords = 0;

old_passwords 系统变量值决定了 PASSWORD() 函数采用的哈希方法。如果 SET PASSWORD 命令拒绝密码因格式不正确而无法设置,则需要更改 old_passwords 的值来更改哈希方法。例如,如果账户使用 mysql_native_password 插件,则必须将 old_passwords 的值设为 0:

SET old_passwords = 0; SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('mypass'); 如果 old_passwords 的值与认证插件要求的不同,则 PASSWORD() 返回的哈希密码不适用于该插件,尝试设置密码会产生错误。例如:

mysql> SET old_passwords = 1; mysql> SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('mypass'); ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number。本节后面将描述允许的 old_passwords 值。

在 MySQL 5.7.5 之前的版本中,可以使用 OLD_PASSWORD() 函数:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接