1. 程式人生 > >windows下修改mysql忘記的密碼

windows下修改mysql忘記的密碼

一、忘記密碼的情況

1、確定mysql服務已經停掉

2.開啟命令列,轉到mysql的bin目錄下;

命令如下:

C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin

C:\Program Files\MySQL\MySQL Server 5.5\bin>


3.輸入:mysqld -nt --skip-grant-tables 
然後回車,如果沒有錯誤資訊,就行了;
注:skip-grant-tables引數用了之後,就可以跳過登入校驗; 

命令如下:

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld -nt --skip-grant-tables


140317 13:23:11 [Warning] option 'new': boolean value 't' wasn't recognized. Set
 to OFF.

4.再開啟一個命令列(因為剛才那個DOS視窗已經不能動了),同樣轉到mysql的bin目錄下; 
5.直接輸入 mysql 並回車,如果成功,將出現MySQL提示符 >

命令如下:

C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

6.切換到mysql表

命令如下:

mysql>USE mysql;

7.可以修改密碼了,命令如下

UPDATE user SET password=PASSWORD("123456") WHERE user="root";

8.重新整理許可權,不要忘記了,命令如下:

mysql>FLUSH PRIVILEGES;

二、使用者在記得密碼的情況下修改密碼

以root使用者登入,命令:mysql -uroot -p 回車 輸入密碼;
mysql>use mysql;
mysql>UPDATE user SET password=PASSWORD('輸入新密碼') WHERE user='root';
mysql>FLUSH PRIVILEGES;