使用我的MySQL安装,我能够安装并更新mysql用户的密码。我注意到的奇怪行为是,当我从普通用户提示符运行命令mysql -u root -p时,我只得到以下错误
ubuntu@node4:/var/log/mysql$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'但是当我从根提示符运行相同的命令时
ubuntu@node4:/var/log/mysql$ sudo su - root
root@node4:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>当从root用户运行mysql -u root -p命令时,我可以使用root登录,如果我在这里缺少任何配置更改,任何人能告诉我吗?我想使用它作为我的数据库主机,并可能希望使用远程用户连接到这个DB。
正如@Progman所评论的,这里是身份验证插件的输出
mysql> SELECT Host, User, plugin FROM mysql.user
-> ;
+-----------+------------------+-----------------------+
| Host | User | plugin |
+-----------+------------------+-----------------------+
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | auth_socket |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)基于上述情况,我不确定这是否是可以接受的行为?
提亚
发布于 2022-10-30 13:15:11
root用户在MySQL中使用的是由标识符auth_socket指示的Socket Peer-凭据可插入身份验证。使用时,用户不会通过密码进行身份验证(如缓存SHA-2可插入身份验证由caching_sha2_password指示),而是使用用户名登录,用户将登录到主机本身(比如ssh或普通登录)。这是出于MySQL中的MySQL帐户的安全原因,您只能从系统的root帐户登录。
根据您想要做的事情,您可以保留root帐户(MySQL)的原样,并且只有当您在root帐户( system )上登录到系统时,才能使用root帐户(MySQL)访问数据库。对于任何其他MySQL帐户,您都可以使用caching_sha2_password身份验证插件来具有正常的username+password对进行登录。
https://stackoverflow.com/questions/74251813
复制相似问题