The MySQL client cannot create a local UNIX or TCP socket due to OS resource limits, bad permissions, or misconfiguration, blocking any new connection attempt.
MySQL Error 2001: CR_SOCKET_CREATE_ERROR means the client failed to create the UNIX or TCP socket needed to reach the server. Check OS file-descriptor limits, free system resources, confirm the socket path, and retry with the correct protocol. Raising ulimit usually fixes the issue.
Can't create UNIX socket (%d)
The error message "Can't create UNIX socket (%d)" signals that the MySQL client library could not open a new socket file descriptor on the local machine. Creation fails before any network handshake with the server begins.
Because the socket is created on the client side, the root cause typically lies in the operating system or client configuration, not inside the MySQL server itself.
Resolving it requires adjusting OS limits or correcting the socket path.
Operating systems cap the number of open file descriptors per process. When that soft limit is reached, attempts to call socket() fail and MySQL raises CR_SOCKET_CREATE_ERROR. Long-running apps, busy cron jobs, or leaked descriptors often trigger this state.
The error also appears when the configured UNIX socket file path is unwritable or already exists with wrong permissions, or when SELinux/AppArmor policies block socket creation.
On Windows, low ephemeral ports or antivirus hooks can cause similar failures.
First, raise the file-descriptor limit. On Linux, run ulimit -n 4096
for the current shell or set LimitNOFILE=4096
in systemd service units. Verify with lsof
or ss
that descriptors are now available, then retry the client.
If the UNIX socket path is the issue, recreate it with correct ownership, or fall back to TCP by adding --protocol=TCP --port=3306
to your mysql command.
Ensure SELinux is permissive or add the correct policy module.
Batch ETL jobs often leak file descriptors. Restarting the job or container frees resources, but the long-term fix is to close descriptors properly and monitor usage with lsof -p PID
.
Shared hosting sometimes points the client to /tmp/mysql.sock
, but a system cleanup script deletes it.
Configure socket=/var/run/mysqld/mysqld.sock
in both my.cnf
and client options to keep the socket in a stable path.
Monitor file-descriptor usage with Prometheus node_exporter or monit
. Trigger alerts at 80 percent consumption. Keep ulimit -n
above your peak connection count plus margin.
Standardize socket paths and permissions during deployment scripts. Use systemd RuntimeDirectory=mariadb
to guarantee directory creation with secure permissions at boot.
Error 2002 (CR_CONNECTION_ERROR) appears when the socket exists but the server is unreachable.
Confirm mysqld is running and listening on the same socket or port.
Error 1040 (ER_CON_COUNT_ERROR) arises when the server limit max_connections
is hit. Unlike 2001, 1040 occurs after the socket is created and requires server tuning rather than OS tuning.
.
No. Error 2001 occurs before the client reaches the server. Increase the OS descriptor limit instead.
Yes. Use --protocol=TCP
with a host of 127.0.0.1 to force TCP and avoid local socket creation.
Run lsof -p $(pgrep mysqld)
or cat /proc/$(pgrep mysqld)/limits
to view descriptor counts and limits.
Galaxy runs SQL clients in managed processes, automatically setting sensible ulimits and exposing connection diagnostics, reducing the chance of CR_SOCKET_CREATE_ERROR in daily workflows.