[Linux]MySQL设置本机登录不需要密码,方便运维

2021-09-21 639点热度 0人点赞 0条评论

为了运维方便,我们登录了MySQL的Linux上后,希望进入MySQL不需要有密码了(因为登录SSH就需要验证了,就不需要再验证MySQL密码)

之前的文章介绍了MySQl5.7使用空密码或者简单的密码:https://blog.terrynow.com/2021/09/18/mysql-set-root-localhost-password-empty-shutdown-password-policy-requirement/

发现MySQL8后,已经不管用了,不过有几个其他的解决方案

  • 修改密码复杂度的Policy(但是不能置空密码)
mysql> set global validate_password_policy=LOW;       # 关闭密码复杂性策略
mysql> set global validate_password_length=6;      # 设置密码复杂性要求密码最低长度为6
mysql> select @@validate_password_policy;          # 查看密码复杂性策略
mysql> select @@validate_password_length;          # 查看密码复杂性要求密码最低长度大小

这样可以把密码设置成123456这样的了,但是确实针对所有用户都是这样了,降低了安全性,所以不推荐这样做

  • (推荐)MySQL client的配置文件把root密码写好,本机连接MySQL就不用输入密码了

修改/etc/my.cnf

增加如下段:

[client]
user=root
password=Abc12&61

这样直接能登录了,也不降低安全性

[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 60415
Server version: 8.0.26 MySQL Community Server (GPL)

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

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

MySQL [(none)]> exit
Bye
[root@localhost ~]#

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论