MySQL忘記root密碼不重啟mysqd重設root密碼

來源:互聯網
上載者:User

找回丟失mysql root密碼
一、啟動修改丟失的mysql單一實例root密碼方法;
1.首先停止mysql
/etc/init.d/mysql stop
2.使用--skip-grant-tables啟動mysql,忽略授權登入驗證
mysqld_safe --skip-grant-tables --user=mysql & --提示:在啟動時加--skip-grant-tables 參數,表示忽略授權驗證
3.進入資料庫系統
shell>mysql
4.修改mysqlroot密碼:update
mysql>update mysql.user set password=password("123456") where user='root' and host='localhost';
mysql>flush privileges;
shell>mysqladmin -uroot -p123456 shutdown
5.重新啟動mysql
shell>/etc/init.d/mysql start
shell>mysql -uroot -p123456
二、多執行個體丟失密碼的方法:
1.關閉mysql
mysqld_mulit stop
2.啟動時加--skip-grant-tables參數
mysqld_safe --defaults-files=/data/mysql/mysql3377/mysql3377.cnf --skip-grant-tables &
mysql -uroot -p -S /tmp/mysql3377.sock <==登入時空密碼
3.修改密碼方法:
update mysql.user set password=password("123456") where user='root'
flush privileges;
4.重啟服務用新密碼登入:
killall mysqld
mysqld_mulit restart 3377


三、不重啟mysqld的方法

1、首先得有一個可以擁有修改許可權的mysql資料庫帳號,當前的mysql執行個體帳號(較低許可權的帳號,比如可以修改test資料庫)或者其他相同版本執行個體的帳號。把data/mysql目錄下面的user表相關的檔案複製到data/test目錄下面。

[root@localhost mysql]# cp mysql/user.* test/
[root@localhost mysql]# chown mysql.mysql test/user.*
2、使用另一個較低許可權的帳號連結資料庫,設定test資料庫中的user儲存的密碼資料。


[root@localhost mysql]# mysql -utest -p12345
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password('yayun') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5  Changed: 0  Warnings: 0

mysql>

3、把修改後的user.MYD和user.MYI複製到mysql目錄下,記得備份之前的檔案。

mv mysql/user.MYD mysql/user.MYD.bak
mv mysql/user.MYI mysql/user.MYI.bak
cp test/user.MY* mysql/
chown mysql.mysql mysql/user.*
4、尋找mysql進程號,並且發送SIGHUP訊號,重新載入許可權表。

[root@localhost mysql]# pgrep -n mysql
2184
[root@localhost mysql]#
[root@localhost mysql]# kill -SIGHUP 2184
5.登陸測試


[root@localhost mysql]# mysql -uroot -pyayun
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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>

聯繫我們

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