首页 > 技术文章 > Ubuntu 16.04 Mysql 重置密码 - -起风了

bing-yu12 2019-10-09 13:42 原文

以下的处理,是在mysql 的mysql.user表的 加密使用的是mysql_native_password的情况,如果不是请参考文章的末尾 部分:

 

1. 登录不到mysql内的情况下,非生产环境,建议修改配置文件/etc/mysql/my.cnf

[mysqld]的地方添加:

skip-grant-tables

然后重启mysql

sudo service mysql restart 

 直接免密码进入数据库:

mysql 

按照其他人的教程是:

update user  set password=password("new_passsword")  where user = 'root';

flush privileges;

重启mysql即可。

但是在有的mysql.user表中,password列会被authentication_string 列名代替,这就要我们手动修改一下上述的列名即可。

 

update  user set authentication_string=password("new_passoword") where user = "root";
flush privileges;

  

ok ,完活!

2.可以进入mysql修改root

步骤同上。

密码修改完毕以后,记得要将上述的

skip-grant-tables

 注释掉,然后重启mysql 

 

授权 子用户的语法格式 :

grant all privileges on databases_name.*  to user_name@'allow_ip' identified by 'password';

  

Attention :

如果多次处理,用户的密码仍旧不正确,请在跳过密码登录后,查看表

select * from mysql.user\G

  查看root用户的plugin 列,采用的加密规则,如果不是mysql_native_password ,那么需要修改;

sql语句如下:

use mysql;
update user set plugin='mysql_native_password' where user = 'root';

 问题 就可以解决喽

推荐阅读