[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