解决方法: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 rootwelcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 295server version: 5.0.56-log source distributioncopyright (c) 2000, 2017, oracle and/or its affiliates. all rights reserved.oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners.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 selectedmysql> use mysql;database changedmysql> update user set password=password('123456') where user='root';query ok, 3 rows affected (0.00 sec)rows matched: 3 changed: 3 warnings: 0mysql> flush privileges;query ok, 0 rows affected (0.00 sec)mysql> exit
3.到 my.cnf 中删除 skip-grant-tables 选项,然后重启mysql服务。
至此mysql数据库root用户的密码修改完毕。
【相关推荐:mysql视频教程】
以上就是忘记mysql密码了怎么办的详细内容。