环境
Ubuntu 16.04 i386
1.停止MySQL服务
$ service mysql stop
2.跳过认证启动MySQL服务
$ mysqld_safe --skip-grant-tables
3.免密码登录MySQL
$ mysql -u root
![](https://img.haomeiwen.com/i414166/3dc82ac9f3204e2e.png)
mysql> use mysql;
MySQL 5.7 以前版本
mysql> update user set Password=PASSWORD('new_password') where user='root';
MySQL 5.7 以后版本(Password字段改为了authentication_string)
mysql> update user set authentication_string=PASSWORD('new_password') where user='root';
mysql> flush privileges;
mysql> exit;
4.开启MySQL服务
$ service mysql start
5.使用刚刚重置的新密码登录
$ mysql -u root -p
![](https://img.haomeiwen.com/i414166/fa619db0e2ec0a74.png)
网友评论