MYSQL忘记密码-重置密码
2021/7/15 19:06:00
本文主要是介绍MYSQL忘记密码-重置密码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
问题 -忘记密码:
登录Mysql,密码错误的时候出现错误ERROR 1045 (28000)
mysql -u root -p Enter Password > 'password' 错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
密码忘记了,这样来重置。
解决方法 - 重置密码:
- 修改my.cnf配置文件(默认位置:/etc/my.cnf):
- 在[mysqld]下添加skip-grant-tables
- 重启mysql服务
- systemctl restart mysql
- 登录mysql
mysql -u root -p 不用输入密码,直接回车即可登录成功
- 修改root的密码
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位字符串密码。通过下面方法来重置。
- 先检查root对应的host
mysql> select user,host from user; +---------------+-----------+ | user | host | +---------------+-----------+ | root | localhost | | mysql.session | localhost | | mysql.sys | localhost | | test | % | +---------------+-----------+ 5 rows in set (0.00 sec)
- 修改root密码:
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
MySql8.0开始修改密码又有了变化,user表中加了字段authentication_string,修改密码前要先检查authentication_string是否为空
- 如果authentication_string不为空
update user set authentication_string='' where user='root';--将字段置为空 ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpwd';--修改密码为rootpwd
- 如果authentication_string为空,直接修改
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';
亲测修改成功
这篇关于MYSQL忘记密码-重置密码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-25MySQL报错Duplicate entry '0' for key 'PRIMARY'
- 2024-05-29阿里 Canal 实时同步 MySQL 增量数据至 ClickHouse 数据库
- 2024-05-24在Linux下管理MySQL的大小写敏感性
- 2024-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享