MySql - 使用哈希密码创建用户和数据库的脚本

tig*_*k89 2 mysql

按照此链接的说明,我正在尝试使用以下语法来创建具有密码的用户

DROP DATABASE IF EXISTS forum;
CREATE DATABASE forum;
DELETE FROM mysql.user WHERE Host='localhost' AND User='forum_admin';
#In this way, the password will not be logged in mysql history
SELECT @password:=PASSWORD('forum_admin');
GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost' IDENTIFIED BY PASSWORD '@password';
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)

但是,倒数第二条指令会出现此错误

ERROR 1827 (HY000): The password hash doesn't have the expected format. Check if the correct password algorithm is being used with the PASSWORD() function.
Run Code Online (Sandbox Code Playgroud)

那么,我该如何解决?我不想手动插入结果SELECT @password(如此此处所述),但我想使用这些结果自动创建新用户.

Dan*_*elo 8

您不需要创建哈希,密码已经存储为哈希..这就是新用户的创建方式

 create user forum_admin@'localhost'  identified by 'password' ;
 GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost';
 flush privileges;
Run Code Online (Sandbox Code Playgroud)

在您的代码中:在论坛上更改GRANT ALL PRIVILEGES.*转到'forum_admin'@'localhost'通过密码'@password'识别;

GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost' IDENTIFIED BY PASSWORD 'pass_string';
Run Code Online (Sandbox Code Playgroud)

创建它的另一种方法


fra*_*ank 7

我也遇到这个问题。也许你应该得到你的密码哈希值

mysql> select password('1');
+-------------------------------------------+
| password('1')                             |
+-------------------------------------------+
| *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
+-------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

然后执行授权命令

mysql> grant all 
-> on *.*
-> to xiushanfan identified by password '*xxxxxxxxxxx(copy from above)' 
-> with grant option;
Run Code Online (Sandbox Code Playgroud)

一切都会好起来的。

这是链接:http : //shareolite.blogspot.com/2014/03/how-to-solve-mysql-error-1827-hy000.html

祝你好运!