** 确保服务器安全 **
** 最好断开网络 本机操作 **

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vi /etc/my.cnf 
#在[mysqld]的段中加上一句:skip-grant-tables
/etc/init.d/mysqld restart

mysql
> USE mysql ;
> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
> flush privileges ;
> quit

vi /etc/my.cnf
#将刚才在[mysqld]的段中加上的skip-grant-tables删除

/etc/init.d/mysqld restart