MySQL error 2002 (CR_CONNECTION_ERROR) means the client cannot connect to the local MySQL server, usually because the socket path, host, port, or server process is incorrect or unavailable.
MySQL Error 2002: CR_CONNECTION_ERROR signals the client cannot reach the local MySQL server via the expected socket or TCP port. Confirm mysqld is running, verify the socket file or host and port, and update the client or my.cnf path to restore the connection.
Can't connect to local MySQL server through socket '%s' (%d)
MySQL error 2002 appears when the client library tries to open a network or UNIX-socket connection but fails. The accompanying message, "Can't connect to local MySQL server through socket '%s' (%d)", tells you which socket file or TCP endpoint it attempted.
This is a client-side error raised before authentication. It indicates the server process is unreachable, the socket file path is wrong, or the TCP port is closed.
Fixing it quickly restores database availability for applications and scripts.
.
The error usually arises when mysqld is not running, has crashed, or is listening on a different path or port. Misconfigured my.cnf files, wrong --socket parameters, and firewall rules are frequent culprits.
It can also occur after upgrades that change the default socket location, when Docker containers map ports incorrectly, or when file permissions block access to the .sock file.
First verify the server is running: systemctl status mysqld or docker ps. If it is down, start or restart it. Next, confirm the socket path with ps -ef | grep mysqld and match it to client settings in /etc/my.cnf or ~/.my.cnf.
If you use TCP, test with telnet 127.0.0.1 3306. Open the port in the firewall if the connection times out. Update client commands with --host=127.0.0.1 --port=3306 to bypass socket issues.
After macOS Homebrew upgrades, mysqld may relocate its socket to /tmp/mysql.sock. Point the client there or create a symlink. Inside Docker, map 3306 correctly and connect to the container IP, not localhost.
For Galaxy users, set the correct socket or TCP parameters in the connection dialog. Galaxy saves these settings, preventing repeated errors and making collaboration seamless.
Always run mysqld under a process manager and enable automatic restarts. Keep a single authoritative my.cnf and document socket paths. Use TCP 127.0.0.1 connections in scripts for portability.
Monitor the MySQL port with a health probe and alert on downtime. Galaxy’s SQL editor surfaces connection issues immediately, allowing quick fixes before they impact shared queries.
Error 2003: CR_CONN_HOST_ERROR arises when connecting over TCP to a remote host. It often shares the same root causes but involves network routing or firewalls.
Error 2006: MySQL server has gone away occurs after a successful connection drops. Tuning wait_timeout and net_write_timeout prevents it.
The server process is stopped, crashed, or failed to start during boot, leaving no socket or listening port.
The client looks for /var/run/mysqld/mysqld.sock while the server created /tmp/mysql.sock after an upgrade.
A local firewall or Docker network rule prevents TCP connections to 127.0.0.1:3306.
The client UID lacks read/write access to the .sock file, especially after running mysqld under a different user.
Multiple my.cnf files override each other, causing the client and server to reference different sockets or ports.
.
Certain installations default to /tmp for easier access. Update my.cnf or create a symlink if your client expects /var/run.
Yes. Connect with --protocol=TCP or set host to 127.0.0.1. This bypasses socket lookup entirely.
Restarting is generally safe during maintenance windows. Always flush logs and inform applications to minimize impact.
Galaxy surfaces detailed error messages in the editor and lets you save multiple connection profiles, reducing misconfigurations across teams.