1. 停止mysql服务
[root@db02 data]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS!
2. 使用--skip-grant-tables启动mysql,忽略授权登录验证
[root@db02 data]# mysqld_safe --skip-grant-tables --user=mysql >/dev/null 2>&1& [1] 30246
3. 登录mysql,修root密码
[root@db02 data]# mysql mysql> UPDATEmysql.user SET password=PASSWORD("123") WHERE user=‘root‘ andhost=‘localhost‘; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql>flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye
4. 退出mysql,并且重新启动mysql
[root@db02 data]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS! [1]+ Done mysqld_safe --skip-grant-tables --user=mysql > /dev/null 2>&1 [root@db02 data]# /etc/init.d/mysqld start Starting MySQL. SUCCESS!
原文地址:http://wangwh.blog.51cto.com/12427110/1924708