Access denied with correct credentials, what is going on?

倖福魔咒の 提交于 2019-12-11 12:08:03

问题


As root:

GRANT ALL PRIVILEGES ON * . * To 'JKR'@'%' IDENTIFIED BY "";
FLUSH PRIVILEGES;

In PHP:

$con = new PDO("mysql:host=127.0.0.1;dbname=jkr;charset=utf8", "JKR", "");

Error message:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'jkr'' in C:\xampp\www\jkr\core\connect.php:6

Only works as root for some reason ... Also how come I get Access denied for user ''@'localhost'?


回答1:


Most likely you have an anonymous user ''@'localhost' on your system. An anonymous user is a user where the name is ignored.

If you connect to MySQL with JKR coming from localhost it will match you with the anonymous user.

You can check using SELECT User, Host from mysql.user;

See https://dev.mysql.com/doc/refman/5.7/en/connection-access.html for a detailed discussion about the way MySQL matches users and pemissions.




回答2:


in my case the mysql account was REQUIRE SSL; the ssl_ca file (at a minimum) had to be provided. Additional ssl parameters are here: http://dev.mysql.com/doc/refman/5.7/en/secure-connection-options.html



来源:https://stackoverflow.com/questions/35383168/access-denied-with-correct-credentials-what-is-going-on

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!