#/etc/init.d/mysql stop
#cd /usr/local/mysql
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#mysql -u root mysql
mysql > UPPATE user SET password=PASSWORD('newpassword') where USER='root'; mysql > FLUSH PRIVILEGES;
mysql > quit ;
#/etc/init.d/mysql restart
#mysql -u root -p
-------------------------------------------------------------------------------------------------------
情况1:如果忘记了 MySQL 的 root 密码,可以用以下方法重新设置:
情况2:添加了phpmyadmin,登录时使用mysql的用户密码登录,但phpmyadmin不能使用空密码登录,即为mysql的root用户添加密码即可,可直接跳到第3步操作.
步骤:
1. KILL掉系统里的MySQL进程;
2. 用以下命令启动MySQL,以不检查权限的方式启动;
mysqld_safe -skip-grant-tables &
3. 然后用空密码方式使用root用户登录 MySQL;
mysql -u root
4. 修改root用户的密码;
mysql> update mysql.user set password=PASSWORD('新密码') where User='root';
mysql> flush privileges;
mysql> quit
5. 重新启动MySQL,就可以使用新密码登录了