百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> mysql重置root密码
分享文章到:

mysql重置root密码

发布时间:09/01 来源:未知 浏览: 关键词:
关于数据库来说,要是忘怀root会员的密码,那将是非常致命的,但是我们可以通过增加【--ship-grant-tables】参数来跳过权限表,然后从新设定密码并刷新权限即可。

Kill掉MySQL进程,下令如下:

Kill完可以再查看可否还有进程

[root@tse2 tmp]# kill -9 9840 1
[root@tse2 tmp]# ps -ef |grep mysql

倡议停库这种操纵不要影响业务的状况下,停服操纵的,还有最佳这种密码记载好的,可以用keepass保留密码软件!

免费学习视频教程分享:mysql视频教程

然后加跳过权限表参数,重新启动数据库。这样即便不输入密码,也可以进入数据库。

[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
[1] 4854

给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                |
+--------------------+
rows in set (0.01 sec)

相干文章教程举荐:mysql教程

以上就是mysql重置root密码的细致内容,更多请关注 百分百源码网 其它相干文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板