mysql连数据库的时候报错:
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
先登录mysql
mysql -u root -p
输入密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host from user;//查看本机用户
+------------------+-----------+
| user | host |
+------------------+-----------+
| ghl | % |
| ngq | % |
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
注意我的root,host是'%'
我之前执行的是:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
所以报错的现在改成:
SET PASSWORD FOR 'root'@%' = PASSWORD('123456');
完美解决,密码修改成功!