centos mysql忘記密碼,修改密碼


centos mysql忘記密碼,修改密碼

1.修改配置文件my.cnf
[root@localhost ~]# vi /etc/my.cnf
找到mysqld在之后添加
skip-grant-tables
保存退出

2. 重啟mysql服務(必須重啟后才能不需要密碼進入)
systemctl restart mysqld

3.直接登陸mysql而不需要密碼
mysql -u root (直接點擊回車)

4.在mysql中輸入
use mysql;
update user set authentication_string='admin1234' where user='root';
顯示下面信息
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

5.執行 flush privileges;

6.退出mysql ,到my.cnf中把開始添加的skip-grant-tables去掉

7.重啟mysql服務 systemctl restart mysqld

8.重新進入 mysql -u root -p

用修改的密碼還是進入不了
[root@iZwz9env7nl3mi5mxx7yp6Z ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


免責聲明!

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



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