Linux重置mysql账号密码权限、授权远程连接

1、停止mysql服务

systemctl stop mysqld.service

2、查看mysql服务my.cnf

locate my.cnf

3、跳过mysql密码验证

vi /etc/my.cnf

在配置文件中添加 skip-grant-tables
注意要在:[mysqld]标签下加入

                  

4、重启mysql

systemctl restart mysqld.service

 5、登录数据库

mysql -u root -p

 6、选择库

use mysql;

7、重新修改root密码

select host, user, authentication_string, plugin from user; 

alter user user() identified by '复杂的password';

GRANT ALL ON *.* TO 'root'@'%';

GRANT ALL ON 表示所有权限,% 表示通配所有 host,可以访问远程。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234567' WITH GRANT OPTION; 

 8、刷新权限

flush privileges;

9、退出数据库

exit;

10、删除刚才添加的 skip-grant-tables

vi /etc/my.cnf

11、再次重启mysql

systemctl restart mysqld.service

12、查看firewalld状态

systemctl status firewalld

 13、取消防火墙服务锁定

systemctl unmask firewalld;

systemctl status firewalld;

14、设置mysql:3306

firewall-cmd --permanent --zone=public --add-port=3306/tcp

15、刷新

firewall-cmd --reload

如果不行可参考关闭防火墙:
查看防火墙状态: service iptables status
永久性生效,重启后不会复原
开启:chkconfig iptables on
关闭:chkconfig iptables off
即时生效,重启后复原
开启:service iptables start
关闭:service iptables stop
设置后重启:reboot

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西米先生「软件工程师」

您的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值