天天看點

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'; 5.執行 flush privileges; 6.退出mysql ,到my.cnf中把開始添加的skip-grant-tables去掉 7.重新開機mysql服務 systemctl rstart mysqld 8.重新進入 mysql -u root -p

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)

繼續閱讀