Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost'

parknkjun發表於2015-05-12
1、登陸mysql時報如下錯誤:
C:\Users\Administrator>mysql -uroot -p
Enter password: ******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
2、停止mysql服務
net stop mysql5----由於服務名是mysql5
3、修改my.ini檔案
在安裝路徑下找到my.ini檔案,我的是E:\Program Files\MySQL\MySQL Server 5.0
在【mysqld】下面新增一行:skip_grant_tables---跳過密碼驗證
4、登陸資料庫修改密碼
E:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password:                                                       ----這裡可以直接敲回車
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, 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.
mysql> update user set password=password('mysql') where user='root';
ERROR 1046 (3D000): No database selected
mysql> use mysql                                                -----這裡要選擇mysql資料庫
Database changed
mysql> update user set password=password('mysql') where user='root';  ----修改root使用者密碼
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> quit
Bye
E:\Program Files\MySQL\MySQL Server 5.0\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.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, 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.
mysql> update user set password=password('mysql') where user='root';
ERROR 1046 (3D000): No database selected
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
5、將my.ini中的skip_grant_tables刪除
6、重啟mysql5服務
C:\Users\Administrator>net start mysql5
MySQL5 服務正在啟動 .
MySQL5 服務已經啟動成功。
7、登陸資料庫
C:\Users\Administrator>mysql -uroot -p
Enter password: *****                      ----輸入剛剛設定的密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, 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.
mysql> show databases;                ----檢視當前有哪些資料庫
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10271187/viewspace-1651544/,如需轉載,請註明出處,否則將追究法律責任。

相關文章