[root@Perl mysql]# /etc/init.d/mysql stop
[root@Perl mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@Perl mysql]# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
[root@Perl mysql]# /etc/init.d/mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
100202 13:04:33 mysqld ended
STOPPING server from pid file /var/run/mysqld/mysqld.pid
100202 13:04:33 mysqld ended
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
Starting MySQL: [ OK ]
[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@Perl mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit
转载于:https://blog.51cto.com/shaowu/273380