3 months ago
Our database service is not working anymore:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
4 Replies
3 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
3 months ago
Hi there!
that error means your mysql client is trying to connect through a local UNIX socket (/var/run/mysqld/mysqld.sock) — but on Railway your DB is remote, so there’s no local socket to talk to. Instead, connect over TCP using the host/port Railway gives you. Try this (replace the placeholders or use the Railway env vars):
# using explicit values
mysql -h YOUR_HOST -P YOUR_PORT -u YOUR_USER -p
# or (if Railway provides env vars in your shell)
mysql -h $MYSQLHOST -P $MYSQLPORT -u $MYSQLUSER -p
What each flag does:
-h <host> — remote hostname of your Railway MySQL (not 127.0.0.1).
-P <port> — TCP port (usually 3306 unless Railway says otherwise).
-u <user> — MySQL username.
-p — prompts for your password (safer than putting it inline).
a test to confirm the TCP port is reachable (replace YOUR_HOST/YOUR_PORT):
# checks TCP connectivity
nc -vz YOUR_HOST YOUR_PORT
# or
telnet YOUR_HOST YOUR_PORT
where to find the correct values: open your Railway project → MySQL service → Connection Info / Variables. Use those exact MYSQLHOST, MYSQLPORT, MYSQLUSER, and MYSQLPASSWORD values.
If you still see the socket error after this, it means the client is still trying to use the local socket — paste the command you ran (redact the password) and the exact error message and I’ll help debug it fast. If the nc/telnet test fails, paste that output too.
tell me when it connects , I’ll cheer you on :))
