问题
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