1.关闭数据库

# killall mysqld

2.使用--skip-grant-tables启动mysql,忽略授权登录验证。

# mysqld_safe --skip-grant-tables --user=mysql &

3.登入数据库

# mysql

4.修改密码

mysql> update mysql.user set password=password("123456") where user='root' and host='localhost';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

5.重启数据库