mysql忘記root密碼

dotaddjj發表於2012-07-09

Windows上忘記root密碼登陸

C:Userspc>net stop mysql

MySQL 服務正在停止.

MySQL 服務已成功停止。

C:Userspc>e:

E:>cd E:Program FilesMySQLMySQL Server 5.0bin

E:Program FilesMySQLMySQL Server 5.0bin>mysqld-nt --skip-grant-tables

在另一個cmd下進行如下操作:

E:Program FilesMySQLMySQL Server 5.0bin>mysql -u root

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 2 to server version: 5.0.22-community-nt

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| root |

| test |

| xiaoyu |

+--------------------+

5 rows in set (0.11 sec)

mysql> use mysql

Database changed

mysql> update user set password=password('xiaoyu') where user='root';

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

修改生效了,此時重啟mysql服務需要先關閉程式mysql-nt.exe程式,然後才能net start mysql

下面一種方法通用與windowslinuxmysql修改root密碼。

修改mysql的初始化檔案新增

Skip-grant-tables

然後重啟mysql服務即可跳過密碼驗證,後面修改root密碼和前面一樣,修改完後去掉skip-grant-tables

[@more@]

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

相關文章