CentOS 7.7解決yum方式安裝的MySQL 5.7 root用戶密碼丟失問題

1、沒有輸入或輸入錯誤的root用戶密碼,無法進入數據庫:

# mysql -uroot -p

(1)沒有輸入root用戶密碼,直接回車:

image.png

(2)輸入錯誤的root用戶密碼:

image.png

2、強制結束MySQL進程:

# yum -y install psmisc

# killall mysqld

# pkill mysqld

# ps -ef | grep mysql

# ss -tunlp | grep 3306

3、使用mysqld命令,增加--skip-grant-tables參數,跳過權限表,啓動數據庫:

# mysqld --defaults-file=/etc/my.cnf --user=mysql --skip-grant-tables &

# ps -ef | grep mysql

# ss -tunlp | grep 3306

4、使用mysql命令直接進入數據庫,爲root用戶設置新的密碼並刷新權限:

# mysql

mysql> use mysql;

mysql> update user set authentication_string=password('root@1234') where user='root';

mysql> flush privileges;

image.png

5、重啓數據庫:

# killall mysqld

# pkill mysqld

# ps -ef | grep mysql

# ss -tunlp | grep 3306

# systemctl start mysqld

6、輸入root用戶新設置的密碼root@1234,進入數據庫:

# mysql -uroot -p

image.png

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