MySQL root密碼的重置方法
對(duì)于DBA來說,丟失超管用戶root的密碼是致命的,
可以通過添加--ship-grant-tables參數(shù)來跳過權(quán)限表。
1、忘記root密碼,進(jìn)不去數(shù)據(jù)庫(kù):這個(gè)時(shí)候需要強(qiáng)制停庫(kù),先查看MySQL進(jìn)程號(hào)
Kill掉MySQL進(jìn)程,命令如下:
Kill完可以再查看是否還有進(jìn)程
[root@tse2 tmp]# kill -9 9840 1[root@tse2 tmp]# ps -ef |grep mysql
建議停庫(kù)這種操作不要影響業(yè)務(wù)的情況下,停服操作的,還有最好這種密碼記錄好的,可以用keepass保存密碼軟件!
然后加跳過權(quán)限表參數(shù),重啟數(shù)據(jù)庫(kù)。這樣即使不輸入密碼,也可以進(jìn)入數(shù)據(jù)庫(kù)。
[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &[1] 4854
直接輸入mysql不需要密碼即可進(jìn)入
給root用戶設(shè)置新的密碼并刷新權(quán)限,MySQL5.7之后,庫(kù)下的password字段用authentication_string字段代替。
(product)root@localhost:mysql.sock [(none)]> use mysql;Database changed(product)root@localhost:mysql.sock [mysql]> update user set authentication_string=password(’123456’) where user=’root’;Query OK, 0 rows affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 0 Warnings: 1(product)root@localhost:mysql.sock [mysql]> flush privileges;Query OK, 0 rows affected (0.00 sec)
設(shè)置完成之后,重啟數(shù)據(jù)庫(kù)。注意重啟的時(shí)候不需要再加--skip-grant-tables參數(shù)了,正常啟動(dòng)服務(wù),輸入新的密碼可以正常進(jìn)入數(shù)據(jù)庫(kù)了。這邊重啟以后測(cè)試直接mysql沒有密碼是無法進(jìn)入的了。
[root@tse2 bin]# mysqld_safe --deaults-file=/etc/my.cnf &[2] 6720[root@tse2 bin]# 2020-01-16T02:55:45.223195Z mysqld_safe Logging to ’/mysql/mysql3306/logs/error.log’.2020-01-16T02:55:45.262302Z mysqld_safe A mysqld process already exists[2]+ Exit 1 mysqld_safe --deaults-file=/etc/my.cnf[root@tse2 bin]# mysqlERROR 1045 (28000): Access denied for user ’root’@’localhost’ (using password: NO)
這邊輸入密碼連接,即可正常進(jìn)入,是修改后的密碼123456
[root@tse2 bin]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 4Server version: 5.7.23-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, 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.(product)root@localhost:mysql.sock [(none)]> use mysqlDatabase changed(product)root@localhost:mysql.sock [mysql]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys|+--------------------+4 rows in set (0.01 sec)
以上就是MySQL root密碼的重置方法的詳細(xì)內(nèi)容,更多關(guān)于MySQL root密碼重置的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. idea連接sql sever2019圖文教程(超詳細(xì))2. 用Oracle的解析函數(shù)發(fā)現(xiàn)序列間隙3. sqlserver字符串拼接的實(shí)現(xiàn)4. sql與mysql有哪些區(qū)別5. 解決db2事務(wù)日志已滿及日志磁盤空間已滿問題辦法詳解6. Mysql中的concat函數(shù)(拼接函數(shù))詳解7. SQL語句如何實(shí)現(xiàn)超簡(jiǎn)單的多表查詢8. ACCESS 調(diào)用后臺(tái)存儲(chǔ)過程的實(shí)現(xiàn)方法9. 史上超強(qiáng)最常用SQL語句大全10. mysql innodb的重要組件匯總
