开发者

How can I set a password for user in MySQL

开发者 https://www.devze.com 2023-02-16 15:03 出处:网络
I need a password for an user as Drupal\'s installation asks that. I\'m totally newcomer on creating databases so I tried this:

I need a password for an user as Drupal's installation asks that. I'm totally newcomer on creating databases so I tried this:

CREATE DATABASE 'drupaltest';
CREATE USER 'jaakko'@'localhost' IDENTIFIED BY 'password';

But 开发者_开发知识库PHPMyAdmin says

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`password`' 

Could anyone say what queries should I put to make an user with password that Drupal's installation requires and what grants should the new user have?


What you have should work I think. The only things I can think of is maybe you have the wrong type of quotation marks or maybe it has an issue with you setting password to 'password'. Perhaps try set it to something else. If that doesn't work maybe try create the user and then in a separate statement set the password and see if / where it trips up. E.g.

CREATE USER 'jaakko'@'localhost';
SET PASSWORD FOR 'jaakko'@'localhost' = PASSWORD('newpass');

This will also store the password more securely since the hash value will be stored instead of just the plain-text.


Brent777's solution will work, but for added security I would suggest salting the hash with a salt_value.

SELECT users.id, users.name into @id, @name FROM users where users.name = 'jaakko';
CREATE USER 'jaakko'@'localhost';
SET @newpass = 'newpass';
SET PASSWORD FOR 'jaakko'@'localhost' = PASSWORD(concat(@id,@name,@newpass));

Otherwise it will be too easy to attack the password table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号