《Mysql入門MySQL的root密碼忘記怎么辦 修改root密碼的方式》要點(diǎn):
本文介紹了Mysql入門MySQL的root密碼忘記怎么辦 修改root密碼的方式,希望對您有用。如果有疑問,可以聯(lián)系我們。
如果哪天你忘記了線上MySQL數(shù)據(jù)庫的root暗碼,怎么辦?MYSQL教程
大家往往會想到skip-grant-tables參數(shù),具體步驟如下:MYSQL教程
1. 關(guān)閉MySQL數(shù)據(jù)庫,因?yàn)閞oot暗碼忘記了,mysqladmin無法使用,此時(shí),只能通過kill pid關(guān)閉程序.MYSQL教程
在這里,科普一下kill 和kill -9的區(qū)別MYSQL教程
默認(rèn)參數(shù)下,kill 發(fā)送SIGTERM信號給進(jìn)程,告訴進(jìn)程,你需要被關(guān)閉,請自行停止運(yùn)行并退出.
kill -9 發(fā)送SIGKILL信號給進(jìn)程,告訴進(jìn)程,你被終結(jié)了,請立刻退出.與SIGTERM相比,這個信號不能被捕獲或忽略,同時(shí)接收這個信號的進(jìn)程在收到這個信號時(shí)不能執(zhí)行任何清理
所以,萬不得已,不要通過kill -9殺掉進(jìn)程,這可能導(dǎo)致MySQL數(shù)據(jù)庫的物理結(jié)構(gòu)損壞,無法重新啟動.MYSQL教程
2. 在my.cnf文件[mysqld]部分添加skip-grant-tables參數(shù)MYSQL教程
3. 登錄數(shù)據(jù)庫,修改root賬戶的暗碼MYSQL教程
以下是修改root暗碼的三種方式:MYSQL教程
??? 1> mysql> set password for 'root'@'localhost'=password('123'); 無需刷新權(quán)限表MYSQL教程
??? 2> mysql> update mysql.user set password=password("456") where user="root" and host="localhost";MYSQL教程
???????? mysql> flush privileges;MYSQL教程
??? 3> # mysqladmin -u root password "123"MYSQL教程
4. 關(guān)閉數(shù)據(jù)庫,注釋掉skip-grant-tables參數(shù),重新啟動數(shù)據(jù)庫.MYSQL教程
?上面這種方式雖然不錯,但是有個問題,你必須重啟數(shù)據(jù)庫,對于線上環(huán)境,這可能是不被允許的.MYSQL教程
下面來談?wù)劻硪环N方法,有點(diǎn)“黑暗科技”的味道MYSQL教程
這個方法利用的是mysql.user表還是MyISAM引擎的特性.MYSQL教程
1. 將該實(shí)例的mysql.user表copy到另一個實(shí)例的目錄下,譬如,test數(shù)據(jù)庫的目錄下MYSQL教程
MYSQL教程
2. 登錄另一個實(shí)例數(shù)據(jù)庫,修改上述三個文件的權(quán)限,并修改root暗碼MYSQL教程
mysql> select user,host,password from test.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +------+-----------+-------------------------------------------+ 1 row in set (0.00 sec) mysql> update test.user set password=password("hello") where user="root" and host="localhost"; Query OK, 1 row affected (0.15 sec) Rows matched: 1 Changed: 1 Warnings: 0
3. 將上述三個文件copy回源數(shù)據(jù)庫MYSQL教程
MYSQL教程
4. 獲取mysqld的pid,通過kill -HUP `pidof mysqld`方式讓mysqld進(jìn)程重新加載配置文件MYSQL教程
MYSQL教程
[root@keepalived01 ~]# mysql -phello Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@keepalived01 ~]# kill -HUP 4283 [root@keepalived01 ~]# mysql -phello Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2528 Server version: 5.6.26 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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>
通過上述輸出可以看出,kill -HUP之前,直接用暗碼hello登錄被拒絕,kill -HUP之后,就可以直接登錄了.MYSQL教程
當(dāng)然,以上方法僅供參考,在生產(chǎn)上慎用,畢竟平安壓倒一切,天曉得哪里會出現(xiàn)問題.MYSQL教程
以上就是本文的全部內(nèi)容,希望可以幫助大家解決root暗碼忘記的困擾,謝謝大家的閱讀.MYSQL教程
維易PHP培訓(xùn)學(xué)院每天發(fā)布《Mysql入門MySQL的root密碼忘記怎么辦 修改root密碼的方式》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/12676.html