MySQL忘记root密码的找回方法
2023-09-14 08:59:55 时间
(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 -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server 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 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> set password = password('ysj123'); ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> 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 -uroot ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@iZ28dr6w0qvZ ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server 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 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中,密码丢失后无法找回,只能通过上述方式修改密码。
转自:http://www.cnblogs.com/chenqionghe/p/4863274.html
相关文章
- 定时调度MySQL任务的实现方法(mysql的定时任务)
- MySQL用户密码重置指南(mysql用户重置)
- 掌握MySQL本地修改密码技巧(mysql本地修改密码)
- 解密MySQL密码:谁有答案?(mysql的密码是多少)
- MySQL在哪些操作系统上支持运行?(mysql支持的操作系统)
- 查看MySQL安装路径的方法(查看mysql路径)
- MySQL数据库密码安全策略指南(mysql密码安全策略)
- 如何解决MySQL忘记密码的问题(mysql忘记密码了)
- MySQL读取Excel文件的简单方法(mysql读取excel)
- SQL如何转换成MySQL,易学易用(sql转换成mysql)
- 掌握MySQL数据库管理:Shell登录MySQL实践(shell登录mysql)
- 用户MySQL统计新增用户:你需要知道的一切(mysql统计新增)
- MySQL进入数据库:一步一步操作指南(mysql 进去数据库)
- MySQL 中 Cast 函数的使用方法(mysql中cast用法)
- 查MySQL数据库操作增删改查实现完美数据管理(c mysql数据增删改)
- 状态 通过CMD查看MySQL服务器状态的方法(cmd如何看mysql)
- MySQL去除多余空格的方法(mysql中去掉空格)
- MySQL自动填补,导致数据不对齐问题怎么处理(mysql不对齐)
- MySQL多表事务处理技巧与优化(mysql不同表的事物)
- MySQL数据库掌握下划线索引的使用方法(mysql下划线索引)
- 解决MYSQL自启问题的方法(mysql不能自启)
- 解决MySQL存储中文字符问题的方法(mysql不能存汉子)
- MySQL的不等于符号的含义及使用方法(mysql不等于 n)
- 无需登录,轻松修改MySQL密码(mysql不登录修改密码)
- MySQL数据库不支持视图,对应的解决方法与替代方案是什么(mysql不支持视图)