mysql Access denied for user root@localhost錯誤

轉自:http://www.cnblogs.com/m97i/p/7586628.html

C:\AppServ\MySQL> mysql -u root -p 
Enter password:  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

 

解決方法:

編輯mysql配置文件my.ini(在mysql的安裝目錄下,我的在D:\Program Files\MySQL\MySQL Server 5.0\my.ini),在[mysqld]這個條目下加入 skip-grant-tables 保存退出後重啓mysql

1.點擊“開始”->“運行”(快捷鍵Win+R)。

2.停止:輸入 net stop mysql

3.啓動:輸入 net start mysql  

這時候在cmd裏面輸入mysql -u root -p就可以不用密碼登錄了,出現 password:的時候直接回車可以進入,不會出現ERROR 1045 (28000),但很多操作都會受限制,因爲我們不能grant(沒有權限)。

繼續按下面的流程走:

1.進入mysql數據庫:
mysql> use mysql; 
Database changed

2.給root用戶設置新密碼:  
mysql> update user set password=password("新密碼") where user="root"; 
Query OK, 1 rows affected (0.01 sec) 
Rows matched: 1 Changed: 1 Warnings: 0

3.刷新數據庫
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)  

4.退出mysql:
mysql> quit; 
Bye

改好之後,再修改一下my.ini這個文件,把我們剛纔加入的 "skip-grant-tables"這行刪除,保存退出再重啓mysql就可以了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章