一、 首先檢查mysql服務是否啓動,若已啓動則先將其中止服務,可在開始菜單的運行,使用命令:mysql
net stop mysql sql
打開第一個cmd窗口,切換到mysql的bin目錄,運行命令:數據庫
mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --console --skip-grant-tables安全
註釋:ide
該命令經過跳過權限安全檢查,開啓mysql服務,這樣鏈接mysql時,能夠不用輸入用戶密碼。 ui
2、打開第二個cmd窗口,鏈接mysql:spa
輸入命令:orm
mysql -uroot -p
ip
出現:ci
Enter password:
在這裏直接回車,不用輸入密碼。 若是此步驟出現錯誤,請參考下面
而後就就會出現登陸成功的信息,
使用命令:
show databases;
使用命令切換到mysql數據庫:
use mysql;
使用命令更改root密碼:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
刷新權限:
FLUSH PRIVILEGES;
而後退出,從新登陸:
quit
從新登陸:
mysql -uroot -p
出現輸入密碼提示,輸入新的密碼便可登陸:
Enter password: ***********
顯示登陸信息: 成功 就一切ok了
下面爲可能出現錯誤的解決方法
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 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就能夠了。