Linux下修改MySql的root密码

linux下如何修改Mysql的root密码
    今天,忘了mysql下的root密码,想重置一下,但找了多个网站上的方法均有问题,最后参考几家的过程,经过不断尝试获得,终于成功了,下面特将过程分享给大家:
环境:
操作系统:Centos 5.5
数据库:MySQL 5.0.77
  
过程:
1、关闭mysql。
[root@localhost ~]#service mysqld stop
Stopping MySQL:                                            [  OK  ]
 
2、跳过授权表启动mysql,关闭网络监听,让其后台运行或者开个新终端。 
[root@localhost ~]#mysqld_safe --skip-grant-tables --skip-networking
Starting mysqld daemon with databases from /var/lib/mysql
提示:此时按下CTRL-Z
 
[1]+  Stopped                 mysqld_safe --skip-grant-tables --skip-networking
[root@localhost ~]#bg
[1]+ mysqld_safe --skip-grant-tables --skip-networking &
 
3、链接mysql服务器。 
[root@localhost ~]#mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
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  Changed: 3  Warnings: 0
 
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  mysqld ended
 
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
 
 
现在你可以使用新的密码登录mysql了。
原文地址:https://www.cnblogs.com/shijiaoyun/p/3843173.html