Ubuntu 重置MySQL Root密码

环境

Ubuntu 16.04 i386

1.停止MySQL服务

$ service mysql stop

2.跳过认证启动MySQL服务

$ mysqld_safe --skip-grant-tables

3.免密码登录MySQL

$ mysql -u root
Ubuntu 重置MySQL Root密码_第1张图片
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 
Ubuntu 重置MySQL Root密码_第2张图片

你可能感兴趣的:(Ubuntu 重置MySQL Root密码)