centos中忘记mysql登录密码解决方案

忘记登录mysql的密码了

# 显示的输入密码, 查看自己的报错了
mysql -u root -p123456

在这里插入图片描述
第一次安装使用mysql可以使用MySQL的临时密码登录进系统

# 基础linux 命令
# 查看文件内容
# | 管道符, 前者的输出作为后者的输入
# grep 包含或者说是 查找 相应 字段的行
cat /var/log/mysqld.log |grep password

在这里插入图片描述
每个人都不一样
当我们第一次 , 修改过以后, 就会使用我们自己的密码了, 首次登录进系统强制设置密码, 要不然啥也干不了

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> update mysql.user set authentication_string=password('123456@Y') where user='root' ;

密码有要求, 要数字,字母,符号,长度超过八位
那么当你没注意随便设置了, 就好玩了

解决方案

进入mysql的配置文件, 跳过密码检验

vi /etc/my.cnf

在 [mysqld] 配置节 下新增 skip-grant-tables

skip-grant-tables
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

skip-grant-tables

# Disabling symbolic-links is recommended to prevent assorted security risks
"/etc/my.cnf" 29L, 979C written

就这么简单, 就跳过检验了

保存配置文件后,重启mysql服务

systemctl restart mysqld.service

使用mysql的登录命令直接回车进入即可

mysql -u root -p
# 直接回车就好

然后重新修改 mysql 的登录密码

mysql>update mysql.user set authentication_string=password('Yang@123456') where user='root' ;
mysql>flush privileges ;
mysql>quit

再次编辑mysql配置文件,
将之前添加的 skip-grant-tables 去掉。

重启mysql服务。

systemctl restart mysqld.service

参考文档 = https://www.cnblogs.com/yanziwen/p/9215264.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值