环境:
操作系统:Centos 5.5
数据库:MySQL 5.0.77
过程:
1、关闭mysql。
[root@localhost ~]#service mysqld stop
Stopping MySQL:
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 the buffer.
4、使用mysql数据库。
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
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
Stopping MySQL:
Starting MySQL:
[1]+
现在你可以使用新的密码登录mysql了。