linux mariadb忘记密码,Mariadb忘记root密码解决办法

主机环境:

[root@test ~]# lsb_release -a

LSB Version: :core-4.1-amd64:core-4.1-noarch

Distributor ID: CentOS

Description: CentOS Linux release 7.4.1708 (Core)

Release: 7.4.1708

Codename: Core

[root@test ~]# uname -a

Linux test 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

mariadb yum安装参考:https://www.tracymc.cn/archives/614

具体解决过程:

1.首先停止mysql服务进程:

[root@test ~]# systemctl stop mariadb

然后编辑mysql的配置文件my.cnf,找到[mysqld]这个模块,在最后面添加一段代码skip-grant-tables(忽略mysql权限问题,直接登录),最后保存退出.

[root@test ~]# cat /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-grant-tables    //mysqld下面新增这行

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

启动mysql服务:

[root@test ~]# systemctl start mariadb

直接进入mysql数据库,使用mysql库的user表,然后修改mysql的root密码(这里将新密码改为123456):

d36687e18c33b1ee9b31ba896dd13732.png将MySQL的登录设置修改回来,将刚才在[mysqld]的段中加上的skip-grant-tables删除或者注释:

[root@test ~]# cat /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

#skip-grant-tables    //把这行注释

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

重启mysql服务,并用新密码(123456)登录:

189706ce9d0d8290beba2e3187eca9bc.png

至此,密码找回完成.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值