linux下的mysqld配置文件

问题描述

不小心忘记了mysql的密码,重置mysql密码时发现/etc/my.cnf下没有内容,MySQL的配置文件my.cnf默认配置如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important

这时在[mysqld]下添加skip-grant-tables,然后重新启动mysql

systemctl restart mysql

其他问题

发现在mysql8.0中的密码是用cache_sha2_password加密后的密码,而我们使用UPDATE mysql.user SET authentication_string = '123456' WHERE User = 'root';加进去的密码是明文

在这里插入图片描述

1. 安全模式启动

使用管理员权限打开cmd窗口,输入:mysqld --console --skip-grant-tables --shared-memory

2. 刷新权限及退出:flush privileges;
3. 设置数据库密码为空

先把root的密码先设为空:

UPDATE user SET authentication_string = '', plugin = 'caching_sha2_password' WHERE User = 'root';

然后 flush privileges;

再次查看:SELECT Host, User, authentication_string, plugin from user;发现密码空了,然后exit,如下图:

在这里插入图片描述

接下来按ctlc+c退出安全模式(mysqld --console --skip-grant-tables --shared-memory)

mysql -u root 直接回车即可

然后输入:

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456';
flush privileges;
exit 

重启数据库就可以了
这时来查看数据库的密码
在这里插入图片描述

参考链接:https://blog.csdn.net/ligaopan/article/details/135593205

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值