简体   繁体   中英

Mysql root user password set to empty string

I've repeatedly tried to set a password for the root mysql user, originally there was no password at all. However, after resetting it, via code I found from tutorials on the subject:

mysqld_safe --skip-grant-tables &
UPDATE user SET authentication_string=PASSWORD("mypasswordhere") where User='root';
FLUSH PRIVILEGES;

The terminal says I set the password correctly, but when I try to log back in with the password, it doesn't work. What I found is that it's setting the password to an empty string, does anyone know why?

I had some problems to set the password using PASSWORD() function because the validate_password plugin was activated, to bypass this plugin, I created the authentication_string value before setting the new password.

You don't need run mysql in safe mode mysql_safe --skip-grant-tables to change a password, just start normally and try this:

# mysql -uroot

mysql> SELECT PASSWORD('HELLO');
+-------------------------------------------+
| PASSWORD('HELLO')                         |
+-------------------------------------------+
| *C1BCFD6877BB358C0518ECCD6D5A70BFF7D0A174 |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> use mysql;

mysql> update user set authentication_string="*C1BCFD6877BB358C0518ECCD6D5A70BFF7D0A174" where User='root';
mysql> flush privileges;
mysql> quit

# mysql -uroot -pHELLO

mysql> 

Another simple solution is the ALTER USER command:

ALTER USER 'root'@'localhost' IDENTIFIED BY '*C1BCFD6877BB358C0518ECCD6D5A70BFF7D0A174';

If these solutions not work, please show the output from the commands and which MySQL version you using to test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM