MySQL root密码的重置方法
网络编程 2021-07-05 14:37www.168986.cn编程入门
这篇文章主要介绍了MySQL root密码的重置方法,帮助大家更好的理解和学习使用MySQL,感兴趣的朋友可以了解下
对于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.f --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.f & [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.f [root@tse2 bin]# mysql ERROR 1045 (28000): Aess denied for user 'root'@'localhost' (using password: NO)
这边输入密码连接,即可正常进入,是修改后的密码123456
[root@tse2 bin]# mysql -uroot -p Enter password: Wele 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)
以上就是MySQL root密码的重置方法的详细内容,更多关于MySQL root密码重置的资料请关注狼蚁SEO其它相关文章!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指