linux系统的数据库是本地吗,Linux下MySQL无法在本地以非root用户身份连接数据库...

标题有点罗嗦,目前出现的问题如下:

当以非root身份登录数据库时,会报错

mysql -u root -p

Enter password:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

而使用root身份访问就没有问题

问题探究

查看root用户使用的认证插件:

mysql> select user,plugin from user where user = 'root';

+------+-------------+

| user | plugin |

+------+-------------+

| root | auth_socket |

+------+-------------+

1 row in set (0.00 sec)

MySQL使用的auth_socket是通过Unix套接字进行连接认证[1]

The unix_socket authentication plugin works by calling the getsockopt system call with the SO_PEERCRED socket option, which allows it to retrieve the uid of the process that is connected to the socket. It is then able to get the user name associated with that uid. Once it has the user name, it will authenticate the connecting user as the MariaDB account that has the same user name. [2]

因此可以将认证插件改为 mysql_native_password

解决方法

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

FLUSH PRIVILEGES;

另请参阅

[1] https://dev.mysql.com/doc/refman/8.0/en/socket-pluggable-authentication.html

[2] https://mariadb.com/kb/en/authentication-plugin-unix-socket/

标签:socket,plugin,mysql,Linux,以非,user,MySQL,password,root

来源: https://www.cnblogs.com/ZanyRain/p/12243460.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值