設定 root 密碼,啟用 root 使用者進行套接字和 http 訪問

解決以下問題:使用者 root 訪問被拒絕使用密碼是停止 mySQL:

sudo systemctl stop mysql

重新啟動 mySQL,跳過授權表:

sudo mysqld_safe --skip-grant-tables

登入:

mysql -u root

在 SQL shell 中,檢視使用者是否存在:

select User, password,plugin FROM mysql.user ;

更新使用者(所有外掛的外掛為 null):

update mysql.user set password=PASSWORD('mypassword'), plugin = NULL WHERE User = 'root';
exit;

在 Unix shell 中,在沒有授權表的情況下停止 mySQL,然後使用授權表重新啟動:

sudo service mysql stop
sudo service mysql start