如何修改mysql密碼及忘記mysql密碼修改辦法

來源:互聯網
上載者:User

mysql如何設定密碼

有很多方法:
1.用root 進入mysql後
mysql>set password =password('你的密碼');
mysql>flush privileges;

2.使用GRANT語句
mysql>grant all on *.* to 'root'@'localhost' IDENTIFIED BY '你的密碼'with grant option ; www.2cto.com
mysql>flush privileges;

3.進入mysql庫修改user表
mysql>use mysql;
mysql>update user set password=password('你的密碼') where user='root';
mysql>flush privileges;


忘記mysql密碼解決辦法


1、編輯MySQL設定檔:

windows環境中:%MySQL_installdir%my.ini //一般在MySQL安裝目錄下有my.ini即MySQL的設定檔。
linux環境中:/etc/my.cnf

在[MySQLd]配置段添加如下一行:
skip-grant-tables

儲存退出編輯。

2、然後重啟MySQL服務

windows環境中:
net stop MySQL
net start MySQL

linux環境中:
/etc/init.d/MySQLd restart

3、設定新的ROOT密碼

然後再在命令列下執行:
MySQL -uroot -p MySQL
直接斷行符號無需密碼即可進入資料庫了。

現在我們執行如下語句把root密碼更新為 7758521:
update user set password=PASSWORD("7758521") where user='root';

quit 退出MySQL。

4、還原設定檔並重啟服務

然後修改MySQL設定檔把剛才添加的那一行刪除。

再次重起MySQL服務,密碼修改完畢。

修改完畢。

用新密碼7758521試一下吧,又能登入MySQL的感覺就是不一樣吧?

其它解決辦法

重設root密碼
 方法一:
 在my.ini的[mysqld]欄位加入:
skip-grant-tables
重啟mysql服務,這時的mysql不要求輸入密碼即可登入資料庫
 然後進入mysql
mysql>use mysql;
 mysql>更新 user set password=password('新密碼') WHERE User='root';
mysql>flush privileges;
 運行之後最後去掉my.ini中的skip-grant-tables,重啟mysqld即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.