mysql8.0忘记密码如何找回

为了演示,找个测试环境来操作,千万不要线上这么搞
pkill mysqld 关闭掉mysql

跳过MySQL的权限表启动MySQL服务:
–skip-grant-tables启动mysql

/usr/local/mysql8013/bin/mysqld_safe --defaults-file=/data/mysql8/my8.cnf --skip-grant-tables & 
  • 1.

将密码置空:

root@localhost [(none)]>update mysql.user set authentication_string='' where user="root" and host="localhost";
Query OK, 1 row affected (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 0

root@localhost [(none)]>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

pkill mysqld 关闭掉mysql

再次启动mysql服务

[root@localhost ~]# /usr/local/mysql8013/bin/mysqld --defaults-file=/data/mysql8/my8.cnf &
  • 1.

无密码登录MySQL服务并设置新的密码:


root@localhost [(none)]>select version();
+-----------+
| version() |
+-----------+
| 8.0.13    |
+-----------+
root@localhost [(none)]>alter user user() identified by 'jist558@wei';
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

[root@localhost ~]# mysql -uroot -p’jist558@wei’ -e “select version();”
mysql: [Warning] Using a password on the command line interface can be insecure.
±----------+
| version() |
±----------+
| 8.0.13 |
±----------+

密码写入.my.cnf文件就可以mysql直接登录mysql窗口:

[root@localhost ~]# cat .my.cnf 
[mysql]
prompt="\u@\h:\p \R:\m:\s[\d]>"
no-auto-rehash
user=root
password=jist558@wei
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
[root@localhost ~]# mysql -e "select version();"
+-----------+
| version() |
+-----------+
| 8.0.13    |
+-----------+
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

演示完毕

posted @   勤奋的蓝猫  阅读(3)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示