MySQL root密码的重置方法
作者:Tse先生 时间:2024-01-18 14:39:42
对于DBA来说,丢失超管用户root的密码是致命的,
可以通过添加--ship-grant-tables参数来跳过权限表。
1、忘记root密码,进不去数据库:
这个时候需要强制停库,先查看MySQL进程号
Kill掉MySQL进程,命令如下:
Kill完可以再查看是否还有进程
[root@tse2 tmp]# kill -9 9840 1
[root@tse2 tmp]# ps -ef |grep mysql
建议停库这种操作不要影响业务的情况下,停服操作的,还有最好这种密码记录好的,可以用keepass保存密码软件!
然后加跳过权限表参数,重启数据库。这样即使不输入密码,也可以进入数据库。
[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
[1] 4854
直接输入mysql不需要密码即可进入
给root用户设置新的密码并刷新权限,MySQL5.7之后,库下的password字段用authentication_string字段代替。
(product)root@localhost:mysql.sock [(none)]> use mysql;
Database changed
(product)root@localhost:mysql.sock [mysql]> update user set authentication_string=password('123456') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
(product)root@localhost:mysql.sock [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
设置完成之后,重启数据库。注意重启的时候不需要再加--skip-grant-tables参数了,正常启动服务,输入新的密码可以正常进入数据库了。这边重启以后测试直接mysql没有密码是无法进入的了。
[root@tse2 bin]# mysqld_safe --deaults-file=/etc/my.cnf &
[2] 6720
[root@tse2 bin]# 2020-01-16T02:55:45.223195Z mysqld_safe Logging to '/mysql/mysql3306/logs/error.log'.
2020-01-16T02:55:45.262302Z mysqld_safe A mysqld process already exists
[2]+ Exit 1 mysqld_safe --deaults-file=/etc/my.cnf
[root@tse2 bin]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
这边输入密码连接,即可正常进入,是修改后的密码123456
[root@tse2 bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
(product)root@localhost:mysql.sock [(none)]> use mysql
Database changed
(product)root@localhost:mysql.sock [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
来源:https://www.cnblogs.com/Sungeek/p/12199303.html
标签:MySQL,密码,重置,root
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用Python实现数值积分的方法
2023-07-11 10:16:31
![](https://img.aspxhome.com/file/2023/1/66341_0s.png)
安装并免费使用Pycharm专业版(学生/教师)
2023-09-27 08:14:13
![](https://img.aspxhome.com/file/2023/4/94054_0s.png)
简单介绍Python中的RSS处理
2023-03-03 13:59:17
PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数
2023-07-11 03:55:49
Mysql如何查看表及字段信息
2024-01-28 21:35:43
![](https://img.aspxhome.com/file/2023/1/129931_0s.png)
python实现超市商品销售管理系统
2021-01-06 22:18:14
![](https://img.aspxhome.com/file/2023/9/93529_0s.jpg)
oracle中commit之后进行数据回滚的方法
2024-01-25 01:00:53
php自动注册登录验证机制实现代码
2024-04-30 08:48:12
![](https://img.aspxhome.com/file/2023/1/132791_0s.jpg)
django序列化时使用外键的真实值操作
2022-07-19 10:09:30
django配置app中的静态文件步骤
2021-03-15 21:43:57
Python利用redis-py实现哈希数据类型的常用指令操作
2021-09-24 18:16:45
![](https://img.aspxhome.com/file/2023/7/134777_0s.jpg)
Python中Django框架下的staticfiles使用简介
2022-08-18 14:04:40
python os模块简单应用示例
2021-12-20 13:36:48
asp如何让浏览器在https和http之间转化?
2010-05-13 16:37:00
基于Go和PHP语言实现爬楼梯算法的思路详解
2024-05-22 10:18:20
python中函数返回多个结果的实例方法
2023-02-27 14:46:50
JavaScript判断前缀、后缀是否是空格的方法
2024-04-22 22:38:04
使用springboot暴露oracle数据接口的问题
2024-01-28 16:23:28
![](https://img.aspxhome.com/file/2023/9/64439_0s.png)
mysql第一次安装成功后初始化密码操作步骤
2024-01-19 22:20:45
![](https://img.aspxhome.com/file/2023/9/107919_0s.png)
Python处理mat文件的三种方式小结
2022-01-21 23:04:30