The connection in your sample is going to 127.0.0.1, whereas the error message mentions "localhost". Although localhost is usually set to 127.0.0.1, it is still not the same. "localhost" is a name, 127.0.0.1 is an IP and does not require name resolution. Something doesn't add up, the error message does not match your code.

Isn't that at some point this 127.0.0.1 is resolved to "localhost"?I have checked for any references of "localhost" and I cannot find it.

If this is a connection between host A to host B, should I then create another variant of privileges and apart from:CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass'; CREATE USER 'user'@'%' IDENTIFIED BY 'pass';GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'localhost';GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'%';

have also this?:CREATE USER 'user'@'<IP-ADDRESS>' IDENTIFIED BY 'pass';GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'<IP-ADDRESS>';FLUSH PRIVILEGES;

JohnnyBishop wrote:Isn't that at some point this 127.0.0.1 is resolved to "localhost"?

No, its not the same, 127.0.0.1 is NOT resolved as "localhost", its just vice verse, "localhost" is resolved as 127.0.0.1. But 127.0.0.1 is only an IP and it can be assigned to any servername (i.e. wordpress.local, local.joomla, mypc, xampppc etc. etc. etc.). That is the problem, if a connect to 127.0.0.1 fails, it NEVER would report about "localhost".

Anyway, i think the error messages tells, that a CLIENT from localhost fails to connect. But I have no idea why, if its only happening from time to time, there seems to be a problem with Windows TCPIP. I cannot help about that.