当前位置:网站首页>Mysql root 账号如何重置密码
Mysql root 账号如何重置密码
2022-07-04 21:58:00 【Wu_Candy】
今日分享主题:mysql root账号如何重置密码
前两天发现我的 mysql 数据库突然无法登录,但是上周还使用得是正常的,经过一番查找还是没有找到问题的原因。
DBA 给我的解释:我怀疑主机重启后,某些文件(user.*)就丢了,不知道啥原因。我记得之前你也是重启后遇到过相同问题。
既然这样,只好重置 root 账号密码了。具体操作步骤如下
Step1:停止 mysql 服务
命令:systemctl stop mysqld #停掉MySQL
命令:systemctl status mysqld #查看状态
Step2:修改/etc/my.cnf配置,添加 skip_grant_tables=1 启动设置,注意要在[mysqld]行所在的下面添加。
Step3:重启 mysql 并查看状态
systemctl start mysqld systemctl status mysqld
Step4:使用 mysql 命令连接到 mysql 服务器,重新设置root密码
use mysql #进入mysql数据库 select * from user; #查询user表 查看是否有root账号,如果没有就需要操作如下insert into 语句:
insert into `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) values('%','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0','mysql_native_password','*753ACFC7D5D71CB67C49345B035ADFAEA169594B','N','2021-03-08 11:00:04',NULL,'N');
如果 user 表里面有 root 账号,则直接可以重置密码。
命令如下:update user set authentication_string=password('test123') where user='root'
FLUSH PRIVILEGES; #刷新授权列表
再输入 exit 退出mysql
Step5:将步骤2中/etc/my.cnf 文件中添加的 skip_grant_tables=1 启动设置去掉,再执行一个systemctl restart mysql 命令重启 mysql 服务。
Step6:使用重置后的密码再登录时问题解决。
end
边栏推荐
猜你喜欢

Scala download and configuration

How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)

Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history

卷积神经网络模型之——LeNet网络结构与代码实现

bizchart+slider实现分组柱状图

虚拟人产业面临的挑战

嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
![[acwing] solution of the 58th weekly match](/img/e3/fd2c0ffbc9c7ca8a71875882d6c71b.png)
[acwing] solution of the 58th weekly match

HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙

Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
随机推荐
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
283. 移动零-c与语言辅助数组法
Why should garment enterprises talk about informatization?
高中物理:直线运动
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
Interview question 01.01 Determine whether the character is unique
Machine learning notes mutual information
1807. Replace the parentheses in the string
PostgreSQL服务端编程聚合和分组
Kdd2022 | what features are effective for interaction?
关系型数据库
# 2156. Find the substring of the given hash value - post order traversal
Force buckle_ Palindrome number
MySQL存储数据加密
并发网络模块化 读书笔记转
el-tree结合el-table,树形添加修改操作
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
HDU - 1078 fatmouse and cheese (memory search DP)
bizchart+slider实现分组柱状图
能源势动:电力行业的碳中和该如何实现?