登录Mysql,密码错误的时候出现错误ERROR 1045 (28000)
mysql -u root -p Enter Password > 'password' 错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
密码忘记了,这样来重置。
mysql -u root -p 不用输入密码,直接回车即可登录成功
MySQL 5.7 的版本,user表中没有password字段,通过下面的方法来重置root密码
use mysql update user set authentication_string = password(“root”) where user = “root”;
Mysql 5.7.9以后废弃了password字段和password()函数,authentication_string字段表示用户密码,只能是mysql加密后的41位字符串密码。通过下面方法来重置。
mysql> select user,host from user; +---------------+-----------+ | user | host | +---------------+-----------+ | root | localhost | | mysql.session | localhost | | mysql.sys | localhost | | test | % | +---------------+-----------+ 5 rows in set (0.00 sec)
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
MySql8.0开始修改密码又有了变化,user表中加了字段authentication_string,修改密码前要先检查authentication_string是否为空
update user set authentication_string='' where user='root';--将字段置为空 ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpwd';--修改密码为rootpwd
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpwd';--修改密码为rootpwd
如果遇到一下错误
mysql> ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpwd'; ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
则先执行
flush privileges;
然后再执行
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpwd';
亲测修改成功