今天,忘了mysql下的root密码,想重置一下,但找了多个网站上的方法均有问题,最后参考几家的过程,经过不断尝试获得,终于成功了,下面特将过程分享给大家:
环境:
操作系统:Centos 5.5
数据库:MySQL 5.0.77
过程:
1、关闭mysql。
[root@localhost ~]#service mysqld stop
StoppingMySQL:
2、跳过授权表启动mysql,关闭网络监听,让其后台运行或者开个新终端。
[root@localhost ~]#mysqld_safe --skip-grant-tables--skip-networking
Starting mysqld daemon with databases from /var/lib/mysql
提示:此时按下CTRL-Z
[1]+
[root@localhost ~]#bg
[1]+ mysqld_safe --skip-grant-tables --skip-networking&
3、链接mysql服务器。
[root@localhost ~]#mysql
Welcome to the MySQL monitor.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear thebuffer.
4、使用mysql数据库。
mysql>use mysql;
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with -A
Database changed
5、设置root新密码。
mysql>update user set password=password('123')where user='root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3
6、退出mysql。
mysql>quit
bye
7、重起mysql。
[root@localhost ~]#service mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
120928 11:38:28
StoppingMySQL:
StartingMySQL:
[1]+
现在你可以使用新的密码登录mysql了。