博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL忘记root密码的找回方法
阅读量:7108 次
发布时间:2019-06-28

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

(1)登录到数据库所在服务器,手工kill掉MySQL进程:  

kill ' cat /mysql-data-directory/hostname.pid'
其中,/mysql-data-directory/hostname.pid指的是MySQL数据目录下的.pid文件,它记录了MySQL服务的进程号。
(2)使用--skip-grant-tables选项重启MySQL服务:
[root@iZ28dr6w0qvZ mysql]# ./bin/mysqld_safe --skip-grant-tables --user=root &[1] 17299[root@iZ28dr6w0qvZ mysql]# 151006 13:14:41 mysqld_safe Logging to '/alidata/log/mysql/error.log'.151006 13:14:41 mysqld_safe Starting mysqld daemon with databases from /alidata/server/mysql/data
其中--skip-grant-tables选项的意思是启动MySQL服务的时候跳过权限表认证。启动后,连接到MySQL的root将不需要命令。
(3)用空密码的root用户连接到MySQ,并且更新root口令:
[root@iZ28dr6w0qvZ ~]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.5.37-log MySQL Community Server (GPL)  Copyright (c) 2000, 2014, 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> set password = password('ysj123');ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementmysql> update mysql.user set password=password('123456') where user='root' and host='localhost';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0
 此时,由于使用了--skip-grant-tables选项启动,使用“set password”命令更改密码失败,直接更新user表的password字段后更改密码成功。
(4)刷新权限表,使得权限认证重新生效:
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

(5)重新用root登录时,必须输入新口令:

[root@iZ28dr6w0qvZ ~]# mysql -urootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)[root@iZ28dr6w0qvZ ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.5.37-log MySQL Community Server (GPL)  Copyright (c) 2000, 2014, 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://www.cnblogs.com/chenqionghe/p/4863274.html

你可能感兴趣的文章
linker command failed with exit code 1 (use -v to see invocation)
查看>>
播放后台音频
查看>>
2.vo传参模式和ModerDriven传参模式
查看>>
多线程 这一篇仔细看
查看>>
Nokia 920板砖自救(理论上通用,升级Win10成板砖也可以用这个恢复)
查看>>
Anroid搭建一个局域网Web服务器
查看>>
kettle删除资源库中的转换或者作业
查看>>
java的重写规则
查看>>
Java Spring MVC项目搭建(一)——Spring MVC框架集成
查看>>
Base64编码原理与应用
查看>>
物联网产业链八大环节全景图
查看>>
spark dataframe操作集锦(提取前几行,合并,入库等)
查看>>
阿里巴巴
查看>>
__FUNCTION__, __LINE__ 有助于debug的宏定义
查看>>
性能学习笔记(1)
查看>>
伺服电机的调试步骤有哪些
查看>>
php取两个整数的最大公约数算法大全
查看>>
P1525 关押罪犯
查看>>
input子系统驱动学习之中的一个
查看>>
Android--绑定服务调用服务的方法
查看>>