mysql - 操作错误: (1698, "Access denied for user ' cotequotey'@'localhost'“)

标签 mysql database-connection mysql-python mysql-error-1045

即使尝试了此线程中的方法 ERROR 1698 (28000): Access denied for user 'superuser1'@'localhost' ,我的用户名“cotequotey”仍然出现相同的错误,内容如下:

OperationalError: (1045, "Access denied for user 'cotequotey'@'localhost' (using password: NO)")

这个用户名“cotequotey”是我将 auth_socket 插件归因于的用户名,以便该用户名成为默认用户名而不是 root。这就是我的用户表的样子:

mysql> select User,host,plugin, authentication_string from mysql.user;
+------------------+-----------+-----------------------+-------------------------------------------+
| User             | host      | plugin                | authentication_string                     |
+------------------+-----------+-----------------------+-------------------------------------------+
| root             | localhost | mysql_native_password | *B845F78DCA29B8AE945AB9CFFAC24A9D17EB5063 |
| mysql.session    | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| debian-sys-maint | localhost | mysql_native_password | *0C8DDC30A93F5F8834121C4DF8703A051E215166 |
| cotequotey       | localhost | auth_socket           |                                           |
+------------------+-----------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)

因此,当我执行以下命令时,我希望通过“cotequotey”进行的连接无需密码即可工作:

ubuntu:~/environment/RAD_Final (angela) $ mysql -u cotequotey
ERROR 1045 (28000): Access denied for user 'cotequotey'@'localhost'

但是,控制台中的此命令仍然会产生原始错误,所以我想知道是否有人知道解决方案?

我想知道这是否是授予权限问题,因为我的 root 授予权限与 cotequotey@localhost 的权限相同。 不确定这是否会让他们发生冲突。

+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
+---------------------------------------------------------------------------+
| Grants for cotequotey@localhost                                           |
+---------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'cotequotey'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'cotequotey'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------------+

最佳答案

根据the docs :

The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server. If the names do not match, the plugin checks whether the socket user name matches the name specified in the authentication_string column of the mysql.user system table row. If a match is found, the plugin permits the connection. The authentication_string value can be specified using an IDENTIFIED ...AS clause with CREATE USER or ALTER USER.

您的 mysql 帐户名似乎与您的 UNIX 用户名不匹配,并且您没有在 authentication_string 字段中指定替代名称。

附录: 本质上 auth_socket 表示“如果操作系统对你进行了身份验证,MySQL 也会信任你。”完成此操作的默认方法是检查 Linux 帐户名和 MySQL 帐户名是否匹配(这样就没有其他人可以通过声称是您来登录计算机并获得权限)。您可以通过指定备用名称来覆盖此行为,如上面链接的文档中所述。

关于mysql - 操作错误: (1698, "Access denied for user ' cotequotey'@'localhost'“),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57047606/

相关文章:

PHP:防止数据库溢出

php - 如何从 MySQL Fetch 数组中获取前 3 个

postgresql - 无法从客户端连接到 PostgreSQL - 错误超时

vb.net - 如何检查与数据库的连接是否打开?

python - 将制表符分隔的值插入数据库

php - 如何正确对 mysql 表进行分组/排序

mysql - 优化对大型数据集的查询——使用 JOIN 还是 IN?

java - 连接到 JDBC MySQL 数据库

mysql - SQL - 没有主键的串联

Python MySQLdb 游标.lastrowid