暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysql 忘记密码处理办法

原创 抖草 2023-06-13
503

MySQL忘记root密码的处理办法

1.编辑/etc/my.cnf文件

1)在[mysqld]下添加以下内容:

skip-grant-tables

2)重启mysql服务

# service mysqld restart

Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

2.直接进入mysql

# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 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 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.修改回密码

1)查看密码

mysql> select user,host,authentication_string from mysql.user;

+---------------+-----------+-------------------------------------------+
| user          | host       | authentication_string                   |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

2)修改密码
情况一:mysql 5.7.6 or later版本

mysql> update mysql.user set authentication_string=password('P@ssw0rd') where user='root';

情况二:mysql 5.7.5 or earlier版本

mysql> update mysql.user set password=password("P@ssw0rd") where user="root" and host="localhost";

4.修改配置文件,重启MySQL

1)修改my.cnf文件
删除或注释skip-grant-tables
2)重启mysql

# service mysqld restart

Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

3)新密码验证

# mysql -uroot -p'P@ssw0rd'

---- end ----

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论