当前位置:网站首页>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
边栏推荐
猜你喜欢

With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

国产数据库乱象
![[advanced C language] array & pointer & array written test questions](/img/3f/83801afba153cfc0dd73aa8187ef20.png)
[advanced C language] array & pointer & array written test questions

常用的开源无代码测试工具

【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用

可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成

Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
随机推荐
What is business intelligence (BI), just look at this article is enough
力扣2_1480. 一维数组的动态和
面试题 01.08. 零矩阵
283. Moving zero-c and language assisted array method
TLA+ 入门教程(1):形式化方法简介
使用 BlocConsumer 同时构建响应式组件和监听状态
php短视频源码,点赞时会有大拇指动画飘起
HDU - 2859 Phalanx(DP)
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
服装企业为什么要谈信息化?
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
BigFilter全局交易防重组件的介绍与应用
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
el-tree结合el-table,树形添加修改操作
1807. 替换字符串中的括号内容
You don't have to run away to delete the library! Detailed MySQL data recovery
i. Mx6ull driver development | 24 - platform based driver model lights LED
国产数据库乱象
TCP协议三次握手过程