MYSQL登录错误:mysqladmin connect to server at ‘localhost’ failed,修改密码,忘记密码
2022/3/7 19:15:13
本文主要是介绍MYSQL登录错误:mysqladmin connect to server at ‘localhost’ failed,修改密码,忘记密码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
[MYSQL登录错误:mysqladmin: connect to server at ‘localhost’ failed]
一、mysql登录错误
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@‘localhost’ (using password: YES)’
解决办法:破解mysql密码
1 [root@localhost ~]# service mysqld stop 2 [root@localhost ~]# mysqld_safe --skip-grant-tables & 3 输入 mysql -uroot -p 回车进入 4 use mysql; 5 \> update user set password=PASSWORD("newpass")where user="root";
5.7及以上版本
\> update mysql.user set authentication_string=password('123') where user='root';
6 更改密码为 newpassord 7 \> flush privileges; 更新权限 8 9 \> exit 退出 10 11 [toot@localhost ~]# service mysqld restart 12 [toot@localhost ~]# mysql -uroot -p新密码进入
二,忘记本地root的登录密码
解决过程:
1、编辑/etc/my.cnf
在[mysqld] 配置部分添加一行
skip-grant-tables
2、保存后重启mysql
[root@localhost ~]# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
3、登录数据库重新设置root密码
1 [root@localhost ~]# mysql -uroot -p mysql 2 Enter password: 3 4 直接回车进入 5 Welcome to the MySQL monitor. Commands end with ; or \g. 8 Your MySQL connection id is 1 9 Server version: 5.1.47-log Source distribution 10 11 Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 12 This software comes with ABSOLUTELY NO WARRANTY. This is free software, 13 and you are welcome to modify and redistribute it under the GPL v2 license 14 15 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 16 17 mysql> show databases; 18 19 **+--------------------+ 20 | Database | 21 +--------------------+ 22 | information_schema | 23 | mysql | 24 | test | 25 +--------------------+ 26 3 rows in set (0.00 sec) 27 执行下列语句 28 mysql> update user set password=password("mysql") where user='root';5.7以前旧版本
mysql>update mysql.user set authentication_string=password('123') where user='root';5.7 以后新版本
29 Query OK, 4 rows affected (0.00 sec) 30 Rows matched: 4 Changed: 4 Warnings: 0 31 mysql> flush privileges; 32 Query OK, 0 rows affected (0.00 sec)
4、删除/etc/my.cnf文件中添加的"skip-grant-tables"行,重启mysql;
用新设的密码就能正常登录了;
————————————————
版权声明:本文为CSDN博主「double_happy111」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/double_happy111/article/details/103496751
这篇关于MYSQL登录错误:mysqladmin connect to server at ‘localhost’ failed,修改密码,忘记密码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-15MySQL教程:初学者必备的MySQL数据库入门指南
- 2024-11-15MySQL教程:初学者必看的MySQL入门指南
- 2024-11-04部署MySQL集群项目实战:新手入门教程
- 2024-11-04如何部署MySQL集群资料:新手入门指南
- 2024-11-02MySQL集群项目实战:新手入门指南
- 2024-11-02初学者指南:部署MySQL集群资料
- 2024-11-01部署MySQL集群教程:新手入门指南
- 2024-11-01如何部署MySQL集群:新手入门教程