Why can't I connect to MySQL server?

Yep, the service is not running on the container you are running this command on, so that console command won’t work. :smile_cat:

What happens is your secondary/database container is spun up, and runs entirely separately from your build container. The only way you can talk to it is via TCP. CircleCI does some networking magic so the containers network stacks are merged, which is why the service is accessible via localhost.

However, the error is here:

Mysql2::Error::ConnectionError: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

You’re trying to access the server via a Unix socket, which only works locally. You need to configure your driver to work over TCP.

1 Like