windows下修改MySQL密碼


 大部分情況下,一般用戶沒有權限更改密碼,只有申請了權限或root用戶纔可以更改密碼;

方法1:用mysqladmin

  mysqladmin -u root password "123456";

  如果root已經設置過密碼,採用如下方法

  mysqladmin -u root -p password  "123456";

方法2: 用SET PASSWORD命令,不需要使用FLUSH PRIVILEGES;

  mysql -u root -p

  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

方法3: 用UPDATE直接編輯user表

      mysql> USE mysql;

      mysql> UPDATE user SET Password = PASSWORD('123456') WHERE user='root';

      mysql> FLUSH PRIVILEGES;


如果在Windows下忘記了MySQL的密碼,可以這樣做:

(1)第一種方法:

1.關閉正在運行的MySQL服務:net stop mysql或在windows任務管理器中結束mysqld.exe進程或在管理工具裏面的服務找到mysql服務,將其停止;

C:\Users\Administrator>net stop mysql
MySQL 服務正在停止.
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>USE mysql;
7.可以修改密碼了:

UPDATE user SET password=PASSWORD("123456") WHERE user="root";
8.刷新權限,不要忘記了:

mysql>FLUSH PRIVILEGES;
9.退出:(退出的方法很多 有quit、exit、ctrl+c、\q 等等);

10.註銷或重啓計算機,然後打開MySQL服務,使用用戶名root和設置的新密碼就可以登錄了。


(2)第二種方法

1.找到mysql的my.ini文件;



2.在my.ini最後面一行添加:


3.重啓mysql服務;

net stop mysql

net start mysql

4.不用密碼就可以登錄了,然後進入後可以修改密碼:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章