mysql5.6密码忘记了该如何恢复
admin
2023-05-20 02:42:03
0

本文主要给大家简单讲讲mysql5.6密码忘记了该如何恢复,相关专业术语大家可以上网查查或者找一些相关书籍补充一下,这里就不涉猎了,我们就直奔主题吧,希望mysql5.6密码忘记了该如何恢复这篇文章可以给大家带来一些实际帮助。

实验环境:

    1、centos7.3

    2、mysql5.6.35

实验描述:

    原mysql仅root账号可以登录且有密码保护,现在密码已经忘记无法找回。今天的目标就是通过破解,重置mysql的root密码。

实验进行时:

    1、开始之前确定mysql不用密码已经不能登录了

[root@c73 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@c73 mysql]#
[root@c73 ~]# mysql -u root -p654321 //用654321这个密码也进不了。
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    2、跳过授权进入mysql

[root@c73 mysql]# systemctl stop mysql //停止mysql
//由于我本身使用的是root账号,mysql运行需要mysql账号所以,增加了--user=mysql,
//这里主要是使用--skip-grant-tables参数跳过授权表
[root@c73 mysql]# mysqld --user=mysql --skip-grant-tables &
[1] 6022
[root@c73 mysql]# 2017-04-11 09:36:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-04-11 09:36:41 0 [Note] mysqld (mysqld 5.6.35) starting as process 6022 ...
2017-04-11 09:36:41 6022 [Note] Plugin 'FEDERATED' is disabled.
2017-04-11 09:36:41 6022 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-04-11 09:36:41 6022 [Note] InnoDB: The InnoDB memory heap is disabled
2017-04-11 09:36:41 6022 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-04-11 09:36:41 6022 [Note] InnoDB: Memory barrier is not used
2017-04-11 09:36:41 6022 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-04-11 09:36:41 6022 [Note] InnoDB: Using Linux native AIO
2017-04-11 09:36:41 6022 [Note] InnoDB: Using CPU crc32 instructions
2017-04-11 09:36:41 6022 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-04-11 09:36:41 6022 [Note] InnoDB: Completed initialization of buffer pool
2017-04-11 09:36:41 6022 [Note] InnoDB: Highest supported file format is Barracuda.
2017-04-11 09:36:41 6022 [Note] InnoDB: 128 rollback segment(s) are active.
2017-04-11 09:36:41 6022 [Note] InnoDB: Waiting for purge to start
2017-04-11 09:36:42 6022 [Note] InnoDB: 5.6.35 started; log sequence number 1626007
2017-04-11 09:36:42 6022 [Note] Server hostname (bind-address): '*'; port: 3306
2017-04-11 09:36:42 6022 [Note] IPv6 is available.
2017-04-11 09:36:42 6022 [Note]   - '::' resolves to '::';
2017-04-11 09:36:42 6022 [Note] Server socket created on IP: '::'.
2017-04-11 09:36:42 6022 [Note] mysqld: ready for connections.
Version: '5.6.35'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

[root@c73 mysql]# netstat -lnpt|grep 3306 //确定服务开启成功
tcp6       0      0 :::3306                 :::*                    LISTEN      6022/mysqld         
[root@c73 mysql]# mysql  //无密码进入mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> //成功进入^_^

    3、修改root密码

mysql> set password for 'root'@'localhost' = password('654321');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
// 在--skip-grant-tables模式下,以上修改密码的方法是行不通了。
// 所以我们直接修改用户表来更新密码。
mysql> update mysql.user set password=password("654321") where user='root';
Query OK, 4 rows affected (0.00 sec) #更新成功了4条root用户的密码
Rows matched: 4  Changed: 4  Warnings: 0
// 最后别忘了刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit //退出
Bye

    4、这时候我们再来用新密码测试看看能不能进入吧

[root@c73 ~]# ps aux|grep mysql
mysql     6022  0.0 11.6 1038816 452312 pts/0  Sl   09:36   0:00 mysqld --user=mysql --skip-grant-tables
root      6113  0.0  0.0 112664   968 pts/1    R+   10:00   0:00 grep --color=auto mysql
[root@c73 ~]# kill -9 6022 //结束掉原来的mysql服务
[root@c73 ~]# systemctl start mysql 以正常模式开启mysql服务
[root@c73 ~]# ps aux|grep mysql
mysql     6132  0.0  0.0 113252  1588 ?        Ss   10:00   0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql     6310  1.8  2.8 698944 110984 ?       Sl   10:00   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      6337  0.0  0.0 112664   972 pts/1    R+   10:01   0:00 grep --color=auto mysql
[root@c73 ~]# mysql #测试不用密码无法进入
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@c73 ~]# mysql -u root -p654321 #测试使用新密码进入成功^_^
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

实验总结:

    密码尽可能的保存好吧,如果是线上24小时不间断的业务,出现这种情况必须重启服务来处理,或多或少都会带来一些不必要的麻烦。

mysql5.6密码忘记了该如何恢复就先给大家讲到这里,对于其它相关问题大家想要了解的可以持续关注我们的行业资讯。我们的板块内容每天都会捕捉一些行业新闻及专业知识分享给大家的。

相关内容

热门资讯

广西柳州发生5.2级地震,南宁... 据中国地震台网正式测定,5月18日0时21分在广西柳州市柳南区发生5.2级地震,震源深度8公里,震中...
购药新规落地!多地药房称买“减... 5月17日消息,近日有消息称,自5月15日起,司美格鲁肽、替尔泊肽等GLP-1药物均需要凭有效期内的...
苹果深夜“放价”:iPhone... 来源:环球网 【环球网科技综合报道】5月15日消息,苹果在深夜毫无预警地打响了一轮价格战,iPho...
原创 从... 进入2026年5月下旬,手机圈即将迎来全年最密集的新品发布窗口。 从今天开始到7月下旬,短短两个月时...
全钢实验台厂家梳理 医疗/科研... 导语:实验室设备选型需兼顾功能适配性与长期稳定性。基于2026年实验室建设行业白皮书及公开市场数据,...
半年内,中方连续迎来安理会“四... 半年内,中方连续迎来联合国安理会“四常”领导人。5月16日,外交部发言人宣布:应中方邀请,俄罗斯总统...
网传有人拍到“野生华南虎”?当... 近期,网络上有人发布消息称,在福建龙岩漳平市永福镇三重岭一带,有村民拍到了野生华南虎影像。消息发布后...
德国马普学会主席:顶尖科学家功... 【文/观察者网 熊超然】香港《南华早报》5月17日报道指出,随着美国遭遇人才流失,地缘政治的迅速变化...
连续10年被拒还要硬蹭WHA?... 第七十九届世界卫生大会(WHA)将于5月18日至23日在瑞士日内瓦举行,不出所料,民进党当局再吃“闭...
新一轮药品集采拉开序幕,个别品... 作者:郭晋晖第十一批国家药品集中带量采购(下称“集采”)落地仅两个多月,随着信息预填报工作的启动,第...