Linux下重置mysql8.0密碼

1. 設置跳過密碼驗證

vim /etc/my.cnf 中添加 skip-grant-tables

重啓:service mysqld restart  

cd  /usr/local/mysql/bin 

進入mysql密碼驗證: ./mysql -u root -p 

因爲設置了跳過密碼驗證,所以此處提醒輸入密碼的時候,直接回車。就可以登錄mysql了。

2. 清空密碼

進入mysql後,切換數據庫至mysql> use mysql;

清空密碼:mysql>update user set authentication_string='' where user='root';

退出mysql:exit

屏蔽skip-grant-tables:vi /etc/my.cnf,在skip-grant-tables前面添加#, 

3、重設密碼爲123456

重啓mysql:mysql>service mysqld restart 

設置密碼:

mysql>ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;

mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

mysql> FLUSH PRIVILEGES;  //立即生效

mysql> exit

重啓mysql:mysql>service mysqld restart 

4. 用你上面設置的密碼(123456)去登錄

[root@centos-linux bin]# ./mysql -u root -p

Enter password: 123456

登錄成功界面:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

也就是說,用剛剛設置的密碼在本地成功的登錄了mysql數據庫。

5. 通過Navicat遠程連接剛剛新增的數據庫

剛剛開始連接是報錯的,此時需要開啓3306端口,然後重新連接,OK。如上圖:

開啓3306端口 :iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

參考:https://blog.csdn.net/dl348/article/details/83752550

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章