Common SQL Errors

MySQL Error 2001: CR_SOCKET_CREATE_ERROR - Causes, Fixes, and Prevention

Galaxy Team
August 5, 2025

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.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 2001: CR_SOCKET_CREATE_ERROR?

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.

Error Highlights

Typical Error Message

Can't create UNIX socket (%d)

Error Type

Connection Error

Language

MySQL

Symbol

CR_SOCKET_CREATE_ERROR

Error Code

2001

SQL State

Explanation

Table of Contents

What is MySQL Error 2001 (CR_SOCKET_CREATE_ERROR)?

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.

What Causes This Error?

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.

How to Fix MySQL Error 2001

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

.

Common Causes

Related Errors

FAQs

Does increasing max_connections fix Error 2001?

No. Error 2001 occurs before the client reaches the server. Increase the OS descriptor limit instead.

Can I bypass the UNIX socket?

Yes. Use --protocol=TCP with a host of 127.0.0.1 to force TCP and avoid local socket creation.

How do I check current file descriptor usage?

Run lsof -p $(pgrep mysqld) or cat /proc/$(pgrep mysqld)/limits to view descriptor counts and limits.

Does Galaxy help prevent this error?

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.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo