Ubuntu 重置MySQL Root密码

环境

Ubuntu 16.04 i386

1.停止MySQL服务

$ service mysql stop

2.跳过认证启动MySQL服务

$ mysqld_safe --skip-grant-tables

3.免密码登录MySQL

$ mysql -u root
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 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容