1、沒有輸入或輸入錯誤的root用戶密碼,無法進入數據庫:
# mysql -uroot -p
(1)沒有輸入root用戶密碼,直接回車:
(2)輸入錯誤的root用戶密碼:
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;
5、重啓數據庫:
# killall mysqld
# pkill mysqld
# ps -ef | grep mysql
# ss -tunlp | grep 3306
# systemctl start mysqld
6、輸入root用戶新設置的密碼root@1234,進入數據庫:
# mysql -uroot -p