一、更改my.cnf配置文件
编辑/etc/my.cnf文件,在[MysqLd]下添加skip-grant-tables,保存退出。
重启MysqL服务:services MysqLd restart
二、更改root密码
重启MysqLd服务后,执行MySQL命令,进入MySQL命令行:
[root@yeebian ~]# MysqL Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 2 Server version: 5.1.73 Source distribution copyright (c) 2000,2013,Oracle and/or its affiliates. All rights reserved. Oracle is a registered Trademark of Oracle Corporation and/or its affiliates. Other names may be Trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MysqL>
修改root密码
MysqL> UPDATE MysqL.user SET Password=PASSWORD('MysqLadmin') where USER='root';
Query OK,0 rows affected (0.00 sec)
Rows matched: 3 Changed: 0 Warnings: 0
MysqL> flush privileges;
Query OK,0 rows affected (0.00 sec)
MysqL> exit
Bye
三、删除/etc/my.cnf中的skip-grant-tables,或者注释掉,重启MysqL即可。