博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 5.7 忘记root密码
阅读量:2429 次
发布时间:2019-05-10

本文共 1500 字,大约阅读时间需要 5 分钟。

背景

今天突然手抖了一下,不小心把navicat中mysql的连接删掉了,当我想再次连接到mysql时才发现密码不记得了。马上百度了一下,发现还是有解决办法的,悬着的心这才放下来。

1.编辑 /etc/my.cnf 文件,在 [mysqld]配置中增加一句 skip-grant-tables

vim /etc/my.cnfsymbolic-links=0log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid# 新增skip-grant-tables

2.重启mysql

systemctl restart mysqld

3.登陆mysql,不用输入用户名,密码,直接回车就可以。

[root@localhost ~]# mysql -uroot Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.28 MySQL Community Server (GPL)Copyright (c) 2000, 2019, 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>

4.重置root密码

mysql> flush privileges;mysql> alter user 'root'@'localhost'   identified by 'your 新密码' ;

5.退出mysql命令行,编辑 /etc/my.cnf 删除 skip-grant-tables,再次重启mysql

# 删除这条配置skip-grant-tablessystemctl restart mysqld

6.使用新密码登陆mysql

[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.28 MySQL Community Server (GPL)Copyright (c) 2000, 2019, 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>

转载地址:http://secmb.baihongyu.com/

你可能感兴趣的文章
程序员:我受够了!不想再在小厂里干Java了!
查看>>
厉害!国内大学生计算机编程第一人,一人挑战一个队,百度最年轻 T10,现创业自动驾驶...
查看>>
研发团队来了高颜值的妹子,这结局万万没想到 | 每日趣闻
查看>>
太难了!开源项目如何商业化?
查看>>
谷歌排名第一的编程语言,死磕它这两点,小白也能学的会!不信你看!
查看>>
程序员掉头发的原因找到了 | 每日趣闻
查看>>
腾讯:我就是那只吃了假辣椒酱的憨憨。老干妈:企鹅你可长点心吧!
查看>>
倒计时1天 | 张钹院士领衔,AI开发者大会20大论坛全攻略!
查看>>
运维工程师的日常?? | 每日趣闻
查看>>
31 道 Java 核心面试题,统统打包给你!
查看>>
太拼了:谷歌第一编程语言小白也能学会!
查看>>
三分钟黑了阿里?马云下死命令留他?吴翰清辟谣:我没黑过阿里
查看>>
如果重新一次高考,你还会选择软件专业当程序员吗? | 每日趣闻
查看>>
如何设计一个安全可靠的 API 接口?
查看>>
一年一度程序员“补课”季来袭,618 背后技术大公开!
查看>>
我和美国 AI 博士聊了聊:2020 年,这件事比存钱更重要!
查看>>
陈芳,高考之后我要学计算机专业,将来做 IT 发财了,我就娶你!
查看>>
“编程能力差的程序员,90%输在这事上!”谷歌AI专家:都是瞎努力!
查看>>
张一鸣做电商:再造一个“抖音”
查看>>
“你写的 Bug 让我来改好吗” | 每日趣闻
查看>>