Linux 下忘记mysql 密码

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。

一、停止 mysql 数据库

/etc/init.d/mysqld stop
service mysql stop

或者直接 kill -9  PID

二、执行命令

mysql_safe --user=mysql --skip-grant-table --skip-networking &

三、使用 root 登录 mysql 数据库

mysql -u root -p

四、更新密码

UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

     新版本更新

 UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';

五、刷新权限

mysql> FLUSH PRIVILEGES;

六、退出重启

quit;

//重启
/etc/init.d/mysqld restart
//重启02
service mysql start

七、授权远程登录mysql

grant all privileges  on *.* to root@'%' identified by "password";
 flush privileges;
原文地址:https://www.cnblogs.com/bytecodebuffer/p/11598324.html