linux修改mysql配置文件_linux下忘记mysql密码后的修改。

b8e913a5f4484ef136e67210ce56b5a5.png

本来是风和日丽、阳光明媚的一天,然后开心的打开测试机捣鼓zabbix,突然一个mysql密码错误扰乱了我的心绪。哎,好烦,要去修改mysql密码了。

首先进入数据库登录时密码忘记,一直报错:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

怎么办啊,试了好久,没搞出来。

那么就去修改mysql的配置文件吧,切换root用户,编辑/etc/my.cnf文件。

在配置文件里面添加skip-grant-tables

0c9520757dfb381eeb78c6b6dcb59c47.png

重启数据库,使用无密码登录。

[root@test]# mysql -uroot

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 1174

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

在mysql的命令行输入:

update mysql.user set password=PASSWORD('新密码')where User='root';

然后在mysql的命令行输入:

flush privileges;

刷新一下权限,并使用quit退出数据库。

最后把/etc/my.cnf文件中的skip-grant-tables删除掉,重启数据库,使用新密码登录。

[root@test ]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 1174

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

mysql的密码修改成功了!

唯一的缺点就是需要重启mysql数据库,所以大家还是一定要记住mysql的密码!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值