MySQL忘記root密碼的找回方法

來源:互聯網
上載者:User

標籤:

    (1)登入到資料庫所在伺服器,手工kill掉MySQL進程:  

kill ‘ cat /mysql-data-directory/hostname.pid‘
    其中,/mysql-data-directory/hostname.pid指的是MySQL資料目錄下的.pid檔案,它記錄了MySQL服務的進程號。     (2)使用--skip-grant-tables選項重啟MySQL服務:
[[email protected] mysql]# ./bin/mysqld_safe --skip-grant-tables --user=root &[1] 17299[[email protected] mysql]# 151006 13:14:41 mysqld_safe Logging to ‘/alidata/log/mysql/error.log‘.151006 13:14:41 mysqld_safe Starting mysqld daemon with databases from /alidata/server/mysql/data
    其中--skip-grant-tables選項的意思是啟動MySQL服務的時候跳過許可權表認證。啟動後,串連到MySQL的root將不需要命令。     (3)用空密碼的root使用者串連到MySQ,並且更新root口令:
[[email protected] ~]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> set password = password(‘ysj123‘);ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementmysql> update mysql.user set password=password(‘123456‘) where user=‘root‘ and host=‘localhost‘;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0
    此時,由於使用了--skip-grant-tables選項啟動,使用“set password”命令更改密碼失敗,直接更新user表的password欄位後更改密碼成功。     (4)重新整理許可權表,使得許可權認證重新生效:
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
     (5)重新用root登入時,必須輸入新口令:
[[email protected] ~]# mysql -urootERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)[[email protected] ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
     注意:在MySQL中,密碼丟失後無法找回,只能通過上述方式修改密碼。 別忘了給個贊哦!~

MySQL忘記root密碼的找回方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.