I want to configure my applications to run on localhost, but only works. localhost gives me a PDO error, or a database connection error, while runs fine. I run into this issue working in a local development environment with both WordPress and Drupal. I'm using mysql with the built in apache server on OSX.

hosts file:       localhost broadcasthost
::1             localhost

from with mysql:

| USER()         | CURRENT_USER() |
| root@localhost | root@localhost |

Typical error:

Warning: PDO::__construct(): MySQL server has gone away

And then when I switch the host entry to the application runs fine.

What I'm looking for is how to leave the host configured as localhost but still connect to the database.

  • 1
    Probably a duplicate of this one: serverfault.com/a/295300/196365 – Alex Oct 18 '16 at 13:08
  • that looks like it's the issue, connecting on TCP instead of unix socket, except the result of netstat -ln | grep 'mysql' is /tmp/mysql.sock. I think this means it's connecting through the socket. I placed a /etc/my.cnf to connect to that socket as well, the result is the same. – icicleking Oct 18 '16 at 17:08
  • Digging in a little further, when I directly connect to mysql from the command line and run the \s command I find that I'm connecting on the unix socket. So perhaps the issue I'm running into is at the application level and not the mysql system. – icicleking Oct 18 '16 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.