C:\AppServ\MySQL> mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user
'root'@'localhost'
(using password: YES)
編輯mysql配置文件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 setpassword=password("新密碼") whereuser="root";
Query OK, 1 rows affected(0.01 sec)
Rows matched: 1 Changed: 1Warnings: 0
3.刷新數據庫
mysql>flush privileges;
QueryOK, 0 rows affected (0.00 sec)
4.退出mysql:
mysql> quit
Bye