简体   繁体   中英

MySQL server denies connections from local PHP script, but not from local MySQL client

This issue has me a bit caught off guard. I've just set up this LAMP server and everything appears to be working well until I try running some of my PHP that communicates with the MySQL server.

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

So obviously the MySQL server won't talk to PHP for some reason. I go ahead and connect to it with MySQL client, and have no issues whatsoever logging in and doing queries. I take a look at the systemctl for MySQL and find that it's purposely denying the connection for some reason.

vultr.guest systemd[1]: Started MySQL Community Server.
vultr.guest mysqld[17740]: warning: cannot open /etc/hosts.allow: Permission denied
vultr.guest mysqld[17740]: warning: cannot open /etc/hosts.deny: Permission denied
vultr.guest mysqld[17740]: refused connect from ::1

Right. So I check the hosts files and their permissions are set to 774, which realistically shouldn't pose any issue. I up the permission to 777 for sake of science and it doesn't seem to make any difference. At this point I'm somewhat at a standstill as I can't find any other leads as to what might be the issue. For the most part all of the configuration is default for PHP and MySQL at the moment, so I honestly can't think of any potential discrepancies arising from their configuration. Anyone willing to share their thoughts on this?

From your log it looks like the connection is made but rejected by mysqld, so this is probably neither a port-issue nor firewall-related.

As far as I know, If you use the command line client to make a connection to a server on localhost, the client always makes the connection through the socket file. PHP on the other hand probably uses TCP/IP.

Maybe there's an error (or some special security measure) in your mysqld configuration that has your mysqld listening on a port but rejects all TCP/IP connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM