当前位置:网站首页>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
边栏推荐
- 并发网络模块化 读书笔记转
- 力扣_回文数
- 常用的开源无代码测试工具
- Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
- 1807. Replace the parentheses in the string
- TLA+ 入门教程(1):形式化方法简介
- From repvgg to mobileone, including mobileone code
- [advanced C language] array & pointer & array written test questions
- MySQL存储数据加密
- 置信区间的画法
猜你喜欢
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
bizchart+slider实现分组柱状图
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
迷失在Mysql的锁世界
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
El tree combined with El table, tree adding and modifying operations
达梦数据凭什么被称为国产数据库“第一股”?
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
随机推荐
Locust性能测试 —— 环境搭建及使用
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
[optimtool.unconstrained] unconstrained optimization toolbox
283. Moving zero-c and language assisted array method
短视频系统源码,点击屏幕空白处键盘不自动收起
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
大厂的广告系统升级,怎能少了大模型的身影
Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
Telephone encryption, middle 4 is replaced by * * * *
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
Sqlserver encrypts and decrypts data
Spatiotemporal prediction 3-graph transformer
TCP protocol three times handshake process
1807. Replace the parentheses in the string
ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
服装企业为什么要谈信息化?
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
什么是商业智能(BI),就看这篇文章足够了
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
力扣98:验证二叉搜索树