幫助中心
這里有最新的使用文檔和教程
Windows下mysql忘記root密碼的解決方法:
Mysql版本:5.1.55-community MySQL Community Server (GPL)
1、 首先檢查mysql服務(wù)是否啟動(dòng),若已啟動(dòng)則先將其停止服務(wù),可在開(kāi)始菜單的運(yùn)行,使用命令:
net stop mysql
或者在windows任務(wù)管理器中結(jié)束mysqld.exe進(jìn)程,或者在控制面板,管理工具里面的服務(wù)找到mysql,將其停止服務(wù)。
打開(kāi)第一個(gè)cmd窗口,切換到mysql的bin目錄,運(yùn)行命令:
mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
注釋:
該命令通過(guò)跳過(guò)權(quán)限安全檢查,開(kāi)啟mysql服務(wù),這樣連接mysql時(shí),可以不用輸入用戶密碼。
"C:Program FilesMySQLMySQL Server 5.1my.ini"指配置文件my.ini,一般在mysql安裝目錄里面。
如:
===============================================================================
C:Program FilesMySQLMySQL Server 5.1bin>mysqld --defaults-file="C:Program FilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
110301 9:20:07 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.
110301 9:20:07 [Note] Plugin 'FEDERATED' is disabled.
110301 9:20:07 InnoDB: Initializing buffer pool, size = 46.0M
110301 9:20:07 InnoDB: Completed initialization of buffer pool
110301 9:20:07 InnoDB: Started; log sequence number 0 44233
110301 9:20:07 [Note] mysqld: ready for connections.
Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)
2、打開(kāi)第二個(gè)cmd窗口,連接mysql:
輸入命令:
mysql -uroot -p
出現(xiàn):
Enter password:
在這里直接回車,不用輸入密碼。
然后就就會(huì)出現(xiàn)登錄成功的信息,
如:
===============================================================================
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.55-community MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
===============================================================================
使用命令:
show databases;
顯示已有數(shù)據(jù)庫(kù):
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
使用命令切換到mysql數(shù)據(jù)庫(kù):
use mysql;
使用命令更改root密碼:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
刷新權(quán)限:
FLUSH PRIVILEGES;
然后退出,重新登錄:
quit
重新登錄:
mysql -uroot -p
出現(xiàn)輸入密碼提示,輸入新的密碼即可登錄:
Enter password: ***********
顯示登錄信息:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 5.1.55-community MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
到這里root密碼就已經(jīng)修改成功了,用Ctrl+C將第一個(gè)cmd窗口結(jié)束,那樣就會(huì)停止mysql服務(wù),如:
=============================================================================== C:Program FilesMySQLMySQL Server 5.1bin>mysqld --defaults-file="C:Program F
ilesMySQLMySQL Server 5.1my.ini" --console --skip-grant-tables
110301 10:29:47 [Warning] '--default-character-set' is deprecated and will be re
moved in a future release. Please use '--character-set-server' instead.
110301 10:29:47 [Note] Plugin 'FEDERATED' is disabled.
110301 10:29:47 InnoDB: Initializing buffer pool, size = 46.0M
110301 10:29:47 InnoDB: Completed initialization of buffer pool
110301 10:29:48 InnoDB: Started; log sequence number 0 44233
110301 10:29:48 [Note] mysqld: ready for connections.
Version: '5.1.55-community' socket: '' port: 3306 MySQL Community Server (GPL)
(此處輸入ctrl+c)
110301 10:30:58 [Note] mysqld: Normal shutdown
110301 10:30:58 InnoDB: Starting shutdown...
110301 10:31:03 InnoDB: Shutdown completed; log sequence number 0 44233
110301 10:31:03 [Note] mysqld: Shutdown complete
Mysql服務(wù)停止了,輸入命令:
net start mysql,即可重新啟動(dòng)mysql服務(wù),如:
===============================================================================
C:Program FilesMySQLMySQL Server 5.1bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。
C:Program FilesMySQLMySQL Server 5.1bin>