linux mysql8忘記密碼的解決方案
1、關(guān)閉mysql登錄驗證
停止mysql
$ systemctl stop mysqld.service
修改/etc/my.cnf,跳過權(quán)限驗證
在my.cnf 下面添加
skip-grant-tables
啟動mysql
$ systemctl start mysqld.service
2、重置mysql密碼
重置root密碼為空
update user set authentication_string='' where user='root';
查看root密碼是否為空
select user, authentication_string from mysql.user;
保存修改
flush privileges;
示例如下:
$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.32 Source distribution Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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 mysql; 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 authentication_string='' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select user, authentication_string from mysql.user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | root | | | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | +------------------+------------------------------------------------------------------------+ 6 rows in set (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> \q Bye
3、開啟mysql登錄驗證
停止mysql
$ systemctl stop mysqld.service
修改/etc/my.cnf,把my.cnf 下面添加的skip-grant-tables刪除
啟動mysql
$ systemctl start mysqld.service
4、修改mysql密碼
使用下面命令登錄,在輸入密碼的那一步直接回車
$ mysql -uroot -p
修改root密碼
‘root’@‘%’: root可以允許任務(wù)機器連接
alter user 'root'@'%' identified by '你的密碼';
查看root密碼
select user, authentication_string from mysql.user;
保存修改
flush privileges;
示例如下:
$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.32 Source distribution Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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 mysql; 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> alter user 'root'@'%' identified by 'mysql.root_2023'; Query OK, 0 rows affected (0.00 sec) mysql> select user, authentication_string from mysql.user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | root | *A780CA81542274F7A6F52BBC40B7B2E2F9BE8A0F | | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | +------------------+------------------------------------------------------------------------+ 6 rows in set (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> \q Bye
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux利用traceroute命令發(fā)現(xiàn)負載均衡的實戰(zhàn)案例
在網(wǎng)絡(luò)管理和故障排除中,了解數(shù)據(jù)包的路徑和識別負載均衡節(jié)點是非常重要的,traceroute 命令是一個用于跟蹤數(shù)據(jù)包在網(wǎng)絡(luò)中經(jīng)過的路由路徑的工具,本文將詳細介紹如何利用 traceroute 命令發(fā)現(xiàn)網(wǎng)絡(luò)中的負載均,需要的朋友可以參考下2024-07-07
重啟Linux服務(wù)器后數(shù)據(jù)消失問題的解決方法(重新掛載)
在使用 reboot 命令重啟服務(wù)器后,服務(wù)器內(nèi)掛載的文件全部丟失,那應(yīng)該如何重新掛載呢?所以本文小編給大家介紹了重啟Linux服務(wù)器后數(shù)據(jù)消失問題的解決方法,并通過圖文講解的非常詳細,需要的朋友可以參考下2024-09-09
詳解如何實現(xiàn)Linux服務(wù)Crash后自動重啟
近期碰到了一個?Linux?Systemd?服務(wù)?Crash,?Crash?后需要人工介入重啟.?那么,?有沒有辦法如何實現(xiàn)?Linux?服務(wù)?Crash?后自動重啟,下面就來和大家分享一下2023-08-08
CentOS7 LNMP+phpmyadmin環(huán)境搭建 第二篇LNMP環(huán)境搭建教程
這篇文章主要為大家詳細介紹了CentOS7 LNMP+phpmyadmin環(huán)境搭建,第二篇LNMP環(huán)境搭建教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07

