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('[email protected]') where user='root'; //修改临时密码
mysql> quit
4、#vi /etc/my.cnf
把新增的skip-grant-tables注释掉
#service mysql restart //重启mysql
# mysql -uroot [email protected] //用临时密码进入mysql
mysql> set password for 'root'@'localhost' =password('[email protected]'); //设置永久密码
mysql> grant all privileges on *.* to [email protected]"%" identified by '[email protected]' with grant option; //设置允许mysql远程连接
mysql> flush privileges;
mysql> quit
#service mysql restart