Linux下重新設置 MySQL 的密碼


1.重置密碼的第一步就是跳過MySQL的密碼認證過程,方法如下:

#vim /etc/my.cnf(注:windows下修改的是my.ini)

很多老鐵,在開始時設置了 MySQL 的密碼,后來一段時間沒有用 MySQL之后,密碼忘了~ QAQ,請別急,現在有以下方法解決密碼忘了的情況。

1.首先我們需要跳過 MySQL 的密碼認證:

(1)進入 /etc/my.cnf 文件

[root@localhost ~]# vim /etc/my.cnf

 

(2)在 [mysqld] 的下面添加 " skip-grant-tables " 用來跳過 MySQL 登錄時候的密碼驗證:

[mysqld]
skip-grant-tables

 

2.重啟下 MySQL :

[root@localhost lib]# systemctl restart mysqld.service

 

3.進入 MySQL 中使用命令對密碼進行修改:

//使用名字叫 mysql(或者自己創建過) 數據庫
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
//這里我把 賬號 root 密碼設置為 root
mysql> update mysql.user set authentication_string=password('root') where user='root' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

// 刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

 

 

4.驗證是否對密碼重新設置成功:

[root@localhost /]# mysql -uroot -proot
//注意:這里一般直接輸入密碼登錄,可能會不安全

mysql: [Warning] Using a password on the command line interface can be insecure.
......

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM