1、修改/etc/my.cnf文件
skip-grant-tables=1
2、登录MySQL,并刷新
#mysql #登录mysql
mysql>FLUSH PRIVILEGES;
3、修改root密码,并刷新
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password@123';
mysql>FLUSH PRIVILEGES;
4、设置远程登录并刷新
mysql>update user set host='%' where user='root';
mysql>FLUSH PRIVILEGES;