1、停止mysql服務。
2,在CMD命令行窗口,進入MYSQL安裝目錄 比如 d:mysql20080505in
3,進入mysql安全模式,即當mysql起來后,不用輸入密碼就能進入數據庫。
命令為: mysqld -nt --skip-grant-tables
***************************************
4,重新打開一個CMD命令行窗口,輸入mysql -uroot -p,使用空密碼的方式登錄MySQL(不用輸入密碼,直接按回車)
5,輸入use mysql。
如果報錯 You must reset your password using ALTER USER statement before executing this statement.
step 1: SET PASSWORD = PASSWORD('your new password');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;
如果沒有報錯,則要進行步驟 6/7/8。
6、輸入以下命令開始修改root用戶的密碼(注意:命令中mysql.user中間有個“點”)
mysql> update mysql.user set password=PASSWORD("新密碼") where User="root";
#修改密碼報錯
ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> update mysql.user set authentication_string=password('*******') where user='*******'; #修改密碼成功 Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
6,刷新權限表
mysql> flush privileges;
7,退出
mysql> quit
或者:
解決Your password has expired. To log in you must change it using a client that supports expired passwords辦法
打開 命令行
- /usr/local/mysql/bin/mysqladmin -u root -p password
/usr/local/mysql/bin/mysqladmin -u root -p password
提示輸入按照后的那個密碼
輸入完成后 提示輸入新的密碼
- Enter password:
- New password:
Confirm new password:
完成