登录
首页 >  数据库 >  MySQL

【MySQL】mysql忘记root密码

来源:SegmentFault

时间:2023-01-10 14:24:50 348浏览 收藏

小伙伴们对数据库编程感兴趣吗?是否正在学习相关知识点?如果是,那么本文《【MySQL】mysql忘记root密码》,就很适合你,本篇文章讲解的知识点主要包括MySQL。在之后的文章中也会多多分享相关知识点,希望对大家的知识积累有所帮助!

mysql数据库忘记root密码的解决方法,步骤如下

① # vim /etc/my.cnf
在[mysqld]下添加skip-grant-tables,然后保存并退出
② 重启mysql服务:service mysqld restart
③ 执行 mysql 命令进入数据库,修改数据库密码
MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root';
如果是MySQL5.7,需要改为MySQL> UPDATE mysql.user SET authentication_string=PASSWORD('新密码') where USER='root';
mysql> flush privileges;
④ 把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql,
即:service mysqld restart
⑤ 下面就可以用root新的密码登录了

[root@ops04 scripts]# vim /etc/my.cnf
[root@ops04 scripts]# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]
[root@ops04 scripts]# 
[root@ops04 scripts]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.22-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> set password=password('000000');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('000000') where USER='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@ops04 scripts]# vim /etc/my.cnf
[root@ops04 scripts]# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]
[root@ops04 scripts]# 
[root@ops04 scripts]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.22-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于数据库的相关知识,也可关注golang学习网公众号。

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表