首页 > 解决方案 > mysql '用户'user'@'localhost'的访问被拒绝(使用密码:YES)'

问题描述

我注意到奇怪的事情。我在 php+mysql 上有用户 jewwishl 的网站。用户 jewwish 可以从 Internet 访问 mysql:

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+-------------------------------------------+
| user             | host      | authentication_string                     |
+------------------+-----------+-------------------------------------------+
| root             | localhost | *PASSWORD                                 |
| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| debian-sys-maint | localhost | *PASSWORD                                 |
| coremgr          | localhost | *PASSWORD                                 |
| phpmyadmin       | localhost | *PASSWORD                                 |
| roundcube        | localhost | *PASSWORD                                 |
| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| jewwish          | localhost | *PASSWORD                                 |
| jewwish          | %         | *PASSWORD                                 |
| jewwishl         | localhost | *PASSWORD                                 |
+------------------+-----------+-------------------------------------------+
10 rows in set (0.01 sec)

我想关闭它。我在 ispmanager 中禁止用户 jewwish 访问互联网,所以我得到了

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+-------------------------------------------+
| user             | host      | authentication_string                     |
+------------------+-----------+-------------------------------------------+
| root             | localhost | *PASSWORD                                 |
| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| debian-sys-maint | localhost | *PASSWORD                                 |
| coremgr          | localhost | *PASSWORD                                 |
| phpmyadmin       | localhost | *PASSWORD                                 |
| roundcube        | localhost | *PASSWORD                                 |
| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| jewwish          | localhost | *PASSWORD                                 |
| jewwishl         | localhost | *PASSWORD                                 |
+------------------+-----------+-------------------------------------------+
9 rows in set (0.00 sec)

但如果我这样做,我会收到错误“无效的授权规范:1045 Access denied for user 'jewwish'@'localhost' (using password: YES)”。可能是什么原因?'jewwish'@'%' 与 'jewwishl'@'localhost' 的关系是什么?

UPD 这里是连接代码:

define("DB_NAME", "jewwish");
define("DB_USER", "jewwishl");
define("DB_PASS", "password");
define("DB_HOST", "localhost");

...
$dbConnection = new PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST.';charset=utf8', DB_USER, DB_PASS);

标签: mysql

解决方案


推荐阅读