MySql教程

mysql8.0 版本忘记密码如何修改密码(与5.7.35版本mysql不同)

本文主要是介绍mysql8.0 版本忘记密码如何修改密码(与5.7.35版本mysql不同),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

mysql8.0版本如何修改密码

    • 第一步:
    • 第二步:
    • 第三步:
    • 第四步:
    • 第五步:

第一步:

在mysql的配置文件中/etc/my.cnf 中 [mysqld] 下加入skip-grant-tables这条命令

vim /etc/my.cnf

[mysqld]
skip-grant-tables

第二步:

重启mysqld服务

service mysqld restart

第三步:

直接进入mysql

mysql -uroot 
use mysql
update user set authentication_string='' where user='root';
exit

update user set authentication_string=’’ where user=‘root’;
使用此条命令清除密码为空

第四步:

进入/etc/my.cnf 将skip-grant-tables 注释 重启服务
因为此时将skip-grant-tables注释掉的话修改密码会报错:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

所以我们需要执行:

vim /etc/my.cnf
[mysqld]
#skip-gant-tables
service mysqld restart

第五步:

直接执行进入mysql 执行命令

mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

必须使用这个命令
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
mysql 8.0中无法使用
1.update mysql.user set authentication_string=password(“123”) where user=‘root’;
2.mysql -uroot -p123.com -e “use mysql;update user set authentication_string=password(‘456’) where user=‘root’;”

这篇关于mysql8.0 版本忘记密码如何修改密码(与5.7.35版本mysql不同)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!