vim /etc/my.cnf文件;
在[mysqld]后添加skip-grant-tables(登錄時跳過權限檢查)
重啟MySQL服務:sudo systemctl restart mysqld
登錄mysql,輸入mysql –uroot –p;直接回車(Enter)
輸入:set password for 'root'@'localhost'=password('admin');
如果報:ERROR 1290 (HY000): The MySQL?server?is running with the --skip-grant-tables option so it cannot execute this statement
輸入:flush privileges;
再次輸入:set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);
為避免麻煩,再次設置遠程訪問
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'Admin123@qwe' WITH GRANT OPTION;
flush privileges;
退出:exit
再把my.ini的skip-grant-tables刪除或者注釋掉
重啟MySQL:sudo systemctl restart mysqld