Linux下MySQL无法在本地以非root用户身份连接数据库
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux下MySQL无法在本地以非root用户身份连接数据库,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1183字,纯文字阅读大概需要2分钟。
内容图文
![Linux下MySQL无法在本地以非root用户身份连接数据库](/upload/InfoBanner/zyjiaocheng/878/cf2928d67aff438ea74ff7d36a1b8ac7.jpg)
标题有点罗嗦,目前出现的问题如下:
当以非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/
内容总结
以上是互联网集市为您收集整理的Linux下MySQL无法在本地以非root用户身份连接数据库全部内容,希望文章能够帮你解决Linux下MySQL无法在本地以非root用户身份连接数据库所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。