溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql怎么重置root密碼

發布時間:2021-09-14 18:23:59 來源:億速云 閱讀:167 作者:chen 欄目:編程語言

本篇內容主要講解“mysql怎么重置root密碼”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“mysql怎么重置root密碼”吧!

對于數據庫來說,如果忘記root用戶的密碼,那將是非常致命的,但是我們可以通過添加--ship-grant-tables參數來跳過權限表。

具體方法如下:

忘記root密碼,進不去數據庫:

這個時候需要強制停庫,先查看MySQL進程號

Kill掉MySQL進程,命令如下:

Kill完可以再查看是否還有進程

[root@tse2 tmp]# kill -9 9840 1
[root@tse2 tmp]# ps -ef |grep mysql

建議停庫這種操作不要影響業務的情況下,停服操作的,還有最好這種密碼記錄好的,可以用keepass保存密碼軟件!

免費學習視頻教程分享:mysql視頻教程

然后加跳過權限表參數,重啟數據庫。這樣即使不輸入密碼,也可以進入數據庫。

[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
[1] 4854

直接輸入mysql不需要密碼即可進入

給root用戶設置新的密碼并刷新權限,MySQL5.7之后,庫下的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)

設置完成之后,重啟數據庫。注意重啟的時候不需要再加--skip-grant-tables參數了,正常啟動服務,輸入新的密碼可以正常進入數據庫了。這邊重啟以后測試直接mysql沒有密碼是無法進入的了。

[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]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

這邊輸入密碼連接,即可正常進入,是修改后的密碼123456

[root@tse2 bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server 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 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.

(product)root@localhost:mysql.sock [(none)]> use mysql
Database changed
(product)root@localhost:mysql.sock [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
rows in set (0.01 sec)

到此,相信大家對“mysql怎么重置root密碼”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女