Mysql 5.7 忘记root密码或重置密码的详细方法
作者:黑甲可宁 时间:2024-01-14 17:02:36
在Centos中安装完MySQL数据库以后,不知道密码,这可怎么办,下面给大家说一下怎么重置密码
1、修改配置文件my.cnf 按i编辑
[root@iZ2ze14tbj23jllo85kuh1Z ~]# vim /etc/my.cnf
在[mysqld]中添加
skip-grant-tables
例如:
[mysqld]
**skip-grant-tables**
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
键盘 Esc 保存修改 :wq退出
2、重启mysql服务
service mysqld restart
3、用户登录
mysql -uroot -p (直接点击回车,密码为空)
选择数据库
use mysql;
下面我们就要修改密码了
以前的版本我们用的是以下修改
update user set password=password('root') where user='root';
但是在5.7版本中不存在password字段,所有我们要用以下修改进行重置密码
update user set authentication_string=password('123456') where user='root';
执行
flush privileges;
4、退出mysql
quit;
5、将最开始修改的配置文件my.cnf中的skip-grant-tables删除
6、重启mysql
7、当你登陆mysql之后你会发现,当你执行命令时会出现
ERROR 1820 (HY000): You must reset your password using ALTER USER statement;
这是提示你需要修改密码
当你执行了
SET PASSWORD = PASSWORD('123456');
如果执行成功后面的就不要看了,纯属浪费时间!
如果出现:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
你需要执行两个参数来把mysql默认的密码强度的取消了才行
set global validate_password_policy=0; set global validate_password_mixed_case_count=2;
这时你再执行
SET PASSWORD = PASSWORD('123456');
以上所述是小编给大家介绍的Mysql 5.7 忘记密码或重置密码的详细方法网站的支持!
来源:http://blog.csdn.net/sun614345456/article/details/53672426
标签:mysql5.7,root,密码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python单个项目列表转换为整数的实现
2023-07-31 20:56:21
![](https://img.aspxhome.com/file/2023/7/133817_0s.png)
Python编程技巧连接列表的八种操作方法
2022-02-10 02:08:54
Win10下Python3.7.3安装教程图解
2023-09-02 18:16:54
![](https://img.aspxhome.com/file/2023/6/62316_0s.jpg)
Python配置pip国内镜像源的实现
2021-09-17 03:21:24
![](https://img.aspxhome.com/file/2023/0/124990_0s.png)
python GUI库图形界面开发之PyQt5表格控件QTableView详细使用方法与实例
2023-02-13 23:39:27
![](https://img.aspxhome.com/file/2023/3/121893_0s.png)
用C++封装MySQL的API的教程
2024-01-25 07:51:51
ASP 常见对象总结(熟悉一下利用以后的开发使用)
2011-03-07 10:57:00
python使用py2neo查询Neo4j的节点、关系及路径
2023-02-01 18:11:52
![](https://img.aspxhome.com/file/2023/5/97195_0s.png)
解决layer弹出层msg的文字不显示的问题
2024-04-23 09:07:51
![](https://img.aspxhome.com/file/2023/3/135933_0s.jpg)
python list等分并从等分的子集中随机选取一个数
2022-07-06 05:24:04
python十进制和二进制的转换方法(含浮点数)
2021-04-03 02:26:24
MySQL判断时间段是否重合的两种方法
2024-01-21 02:41:05
![](https://img.aspxhome.com/file/2023/9/124569_0s.png)
JS中的算法与数据结构之集合(Set)实例详解
2024-04-16 09:28:34
Python pygame 项目实战事件监听
2023-05-31 21:33:20
![](https://img.aspxhome.com/file/2023/8/112908_0s.png)
Python中operator模块的操作符使用示例总结
2023-01-31 12:32:14
python OpenCV实现答题卡识别判卷
2023-12-20 17:27:57
![](https://img.aspxhome.com/file/2023/0/127800_0s.jpg)
MSSQL经典语句
2024-01-22 02:59:12
30种SQL语句优化的方法汇总
2024-01-24 22:55:52
PyQt5的相对布局管理的实现
2022-02-23 08:11:18
![](https://img.aspxhome.com/file/2023/9/86199_0s.png)
简单的前端js+ajax 购物车框架(入门篇)
2024-04-23 09:29:52