1

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'?

BenMorel
  • 30,280
  • 40
  • 163
  • 285
spelgubbe
  • 56
  • 3

2 Answers2

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.

johannes
  • 15,041
  • 3
  • 39
  • 56
1

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

ThorSummoner
  • 12,194
  • 11
  • 114
  • 129