Saturday, December 6, 2014

Set a password to a pre-hashed value in mysql

How can I set a mysql user's password using a pre-hashed password?


=====


I've got a mysql database version 5.1.73 .


According to the mysql documentation, in the newer versions of mysql, creating a user using a prehashed password


CREATE USER 'ans'@'localhost'
IDENTIFIED BY PASSWORD 'hash_string'


is deprecated and will be removed in a future MySQL release.



However, I cannot figure out what (if anything) is the new way to accomplish this.


We use cobbler to set up our databases, and I would like to pre-populate my databases with the accounts they will need, along with the passwords they will use, without having the clear-text passwords in my scripts. I would have thought


update mysql.user
set password = '*E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB'
where user = 'ans';

would do the trick, but from my testing, that doesn't actually change the mysql login password.


mysql> create user 'ans'@'localhost' identified by 'foo';
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| ans | localhost | *F3A2A51A9B0F2BE2468926B4132313728C250DBF |
+------+-----------+-------------------------------------------+
mysql> update mysql.user set password = password('bar') where user = 'ans';
Query OK, 1 row affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| ans | localhost | *E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB |
+------+-----------+-------------------------------------------+
mysql> quit
$ mysql -uans -pbar
ERROR 1045 (28000): Access denied for user 'ans'@'localhost' (using password: YES)
$ mysql -uans -pfoo
Welcome to the MySQL monitor. Commands end with ; or \g.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...