龙空技术网

MySql忘记密码怎么办?

BeginCode 111

前言:

眼前看官们对“忘了mysql的密码”大体比较重视,姐妹们都需要剖析一些“忘了mysql的密码”的相关文章。那么小编同时在网络上搜集了一些有关“忘了mysql的密码””的相关资讯,希望兄弟们能喜欢,你们快快来了解一下吧!

这是一个比较傻的问题,自己安装完MySQL,由于设置了多次密码把密码忘记了,怎么办呢,一顿查解决办法按如下,我的是MySQL8.0.

1、先停止服务

systemctl stop mysqld

2、修改配置文件

修改配置文件,默认文件路径如下/etc/my.cnf增加一行代码  skip-grant-tables 如下[mysqld]skip-grant-tables

3、无密码登录,密码不输入直接回车

[root@begincode etc]# mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 7Server version: 8.0.31 MySQL Community Server - GPLCopyright (c) 2000, 2022, Oracle and/or its affiliates.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> 

4、修改密码

mysql> alter user 'root'@'localhost' identified by '你的密码';ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement如果提示上面这个错误 ,输入下面的命令 然后重试mysql> flush privileges;mysql> alter user 'root'@'localhost' identified by '你的密码';

5、恢复my.cnf文件

6、用新密码登录

其他版本 小于8版本用下面命令尝试

mysql> update mysql.user set password=password('123456') where user='root';

标签: #忘了mysql的密码 #mysql忘记初始密码