Linux · 2009-09-25

忘记Mysql的root密码 重置Mysql密码

停止mysql服务 /etc/init.d/mysqld stop
终止Mysql进程 killall -TERM mysqld

[root@localhost ~]# /usr/bin/mysqld_safe –skip-grant-tables &

mysql -p 回车直接进

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password(‘新密码’) where user=’root’;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit

[root@localhost ~]# service mysqld restart 重启mysql

[root@localhost ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.