忘記mysql 8 密碼,怎么辦

  • vim /etc/my.cnf
    注意不同的系統(tǒng)路徑不太一樣,也有可能是 /etc/my.cnf.d/mysql-server.cnf,根據(jù)自己的實(shí)際情況來(lái)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
# 但都是要在[myqld]這個(gè)節(jié)點(diǎn)下添加
skip-grant-tables
  • 重啟mysql服務(wù):service mysqld restart
  • 免密進(jìn)入mysql
[root@centos8.2 dir]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.26 Source distribution

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

  • 查詢r(jià)oot用戶
mysql> select user,authentication_string,host,plugin from user;
image.png
  • 將root的密碼置為空
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0
  • 然后將第一步文件中的skip-grant-tables去掉,重啟mysql服務(wù): service mysqld restart
  • 現(xiàn)在就可以了無(wú)密碼進(jìn)入msql了
mysql  
//或者  
mysql -u root -p   
password直接回車(chē)  
  • 設(shè)置mysql的新密碼
# 執(zhí)行這個(gè)
ALTER user 'root'@'localhost' IDENTIFIED with mysql_native_password BY '123456'
# 如果上面的報(bào)錯(cuò),改為
ALTER user 'root'@'%' IDENTIFIED with mysql_native_password BY '123456'
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容