美文网首页
Mysql忘记密码时修改密码

Mysql忘记密码时修改密码

作者: liuchungui | 来源:发表于2018-11-07 23:31 被阅读0次

前几天在使用亚马逊服务器的时候,在选择一个Ubuntu环境后,发现内部什么都没有,然后安装了Mysql、php等。在使用Mysql的时候,居然发现第一次没有初始化密码,没法进去。于是,查找以前的笔记没找到,今天记录一次。

1、修改配置文件,使其能无密码进入

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

添加skip-grant-tables

image.png

然后重启mysql

sudo /etc/init.d/mysql restart

2、更新密码

上面设置之后,不需要密码就可以登录。然后,我们使用root用户进入mysql,修改密码。

mysql -u root
# 修改密码
update user set authentication_string=PASSWORD(“你的密码”) where user = root;
# 还有加上这句
update user set plugin = "mysql_native_password";
# 权限生效
flush privileges;

3、验证

进入mysqld.cnf配置文件

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

注释前面添加的skip-grant-tables

image.png

重启服务

sudo /etc/init.d/mysql restart

使用前面设置的密码登录

mysql -u root -p

相关文章

网友评论

      本文标题:Mysql忘记密码时修改密码

      本文链接:https://www.haomeiwen.com/subject/qhzbxqtx.html