Following the instructions at this link, I'm trying to use the following syntax to create an user with a password
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;
However, the penultimate instruction gives this error
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.
So, how can I solve? I don't want to manually insert the result of the SELECT @password
(as explained here or here for example), but I'd like to use those result to create automatically a new user.
Open the MySQL Workbench as an administrator (Right-click, Run as Admin). Click on File>Create Schema to create the database schema. Enter a name for the schema and click Apply. In the Apply SQL Script to Database window, click Apply to run the SQL command that creates the schema.
The password hash stored by MySQL Server is generated by hashing the plain-text password twice using SHA1. When the client transmits the password to the server, it uses three pieces of information: The SHA1 hash of the plain text password. The SHA1 hash of the the SHA1 hash of the plain text password.
You dont need to create the hash, the passwords are already stored as hash.. This is how a new user is created
create user forum_admin@'localhost' identified by 'password' ;
GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost';
flush privileges;
In your code: Change
GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost' IDENTIFIED BY PASSWORD 'pass_string';
to
GRANT ALL PRIVILEGES ON forum.* TO 'forum_admin'@'localhost' IDENTIFIED BY 'pass_string';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With