1、#vi /etc/my.cnf
在[mysqld]下加入一行:skip-grant-tables
2、#service mysql restart //重启mysql
#mysql -uroot -p //不用输入密码直接回车进入mysql
3、mysql> update mysql.user set authentication_string=password('Guanqun@123') where user='root'; //修改临时密码
mysql> quit
4、#vi /etc/my.cnf
把新增的skip-grant-tables注释掉
#service mysql restart //重启mysql
# mysql -uroot -pGuanqun@123 //用临时密码进入mysql
mysql> set password for 'root'@'localhost' =password('Guanqun@123'); //设置永久密码
mysql> grant all privileges on *.* to root@"%" identified by 'Guanqun@123' with grant option; //设置允许mysql远程连接
mysql> flush privileges;
mysql> quit
#service mysql restart