#打开mysql配置文件(配置文件路径可能不一样)vi /etc/my.cnf
#在配置文件最后另起一行并添加以下内容,保存退出
skip-grant-tables
#重启mysql服务;service mysqld restart
#使用mysql命令,并回车mysql
#选中mysql表use mysql;
#查看用户表select host, user, authentication_string, plugin from user;
#将root用户的密码置为空update user set authentication_string='' where user='root';
#退出mysqlexit
#打开mysql配置文件(配置文件路径可能不一样)vi /etc/my.cnf
#删除刚刚添加的那一行内容,保存退出
skip-grant-tables
#重启mysql服务;service mysqld restart
#使用root用户进行登录,因为上面设置了authentication_string为空,所以可以免密码登录;mysql -uroot;
#更新root用户密码为 AAbb123456789!! (5.7版本对密码强度有要求,尽可能的设置为复杂一点),一般情况下root用户只允许在localhost登陆ALTER user 'root'@'localhost' IDENTIFIED BY 'AAbb123456789!!';