MYSQL登入錯誤:mysqladmin connect to server at ‘localhost’ failed,修改密碼,忘記密碼
阿新 • • 發佈:2022-03-07
[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 mysql2 Enter password: 3 4 直接回車進入 5
6 7 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