微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

忘记mysql密码了怎么办

解决方法:1、打开配置文件“my.cnf”,在“[MysqLd]”项下添加“skip-grant-tables”语句,重启MysqL服务;2、执行“MysqL -u root”命令免密码登录数据库;3、使用update命令重置登录密码即可。

本教程操作环境:windows7系统、MysqL8版本、Dell G3电脑。

忘记MysqL密码了怎么办?不怕,可以通过重置密码了重新设置一个新密码,

重置密码的方法

1.修改配置文件 my.cnf,在配置文件 [MysqLd] 下添加 skip-grant-tables,重启MysqL服务即可免密码登录

其中 --skip-grant-tables 选项的意思是启动 MysqL 服务的时候跳过权限表认证。 启动后,连接到 MysqL 的 root 将不需要口令(危险)。

[MysqLd]
skip-grant-tables

2.用空密码的 root 用户连接到 MysqL,并且更改 root 口令

免密码登录MysqL数据库

[root@iZ235wguph2Z www]# MysqL -u root
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 295
Server version: 5.0.56-log Source distribution
copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

重置密码:

MysqL> update user set password=password('123456') where User='root';
ERROR 1046 (3D000): No database selected
MysqL> use MysqL;
Database changed
MysqL> update user set password=password('123456') where User='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
MysqL> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MysqL> exit

3.到 my.cnf 中删除 skip-grant-tables 选项,然后重启MysqL服务。

至此MysqL数据库root用户的密码修改完毕。

【相关推荐:mysql视频教程

原文地址:https://www.jb51.cc/mysql/2915310.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐