How to fix ERROR 2001: Can't create UNIX socket in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 25, 2025· 114 views

ERROR 2001 (CR_SOCKET_CREATE_ERROR) occurs when the MySQL client cannot create or access the UNIX socket file used for local connections. This typically happens when the socket file is missing, has incorrect permissions, or the server isn't running.

Quick fix

Fixes 2001

# Check if MySQL service is running
sudo systemctl status mysql
# or
sudo service mysql status

# On macOS with Homebrew
brew services list | grep mysql

# Check if MySQL process exists
ps aux | grep mysqld
  1. Verify that MySQL server is running
  2. Find the actual socket file location
  3. Verify the socket file exists and check permissions
  4. Fix socket directory and file permissions
mysql — error
# Check if MySQL service is running
sudo systemctl status mysql
# or
sudo service mysql status
# On macOS with Homebrew
brew services list | grep mysql
# Check if MySQL process exists
ps aux | grep mysqld
ERROR 2001: Can't create UNIX socket

What this error means

MySQL ERROR 2001 (CR_SOCKET_CREATE_ERROR) is a client-side connection error that occurs when the MySQL client attempts to establish a local connection via UNIX socket but fails to create or access the socket file. Unlike TCP/IP connections which use network ports, UNIX sockets are special files on the filesystem (typically /var/run/mysqld/mysqld.sock or /tmp/mysql.sock) that enable fast, permission-based local communication between the client and server. This error indicates one of three fundamental problems: (1) the MySQL server is not running, so the socket file doesn't exist, (2) the socket file exists but the client doesn't have permission to access it, or (3) the client is looking for the socket in the wrong location because of configuration mismatches. Unlike connection refused errors that occur when the server is running but unreachable, ERROR 2001 specifically means the client cannot establish the socket file itself.

Typical symptoms

  • MySQL client commands (mysql, mysqldump, etc.) fail immediately with 'ERROR 2001' message
  • Applications cannot connect to MySQL locally, only failing for socket connections (TCP connections might work)
  • Error occurs right after boot when /tmp or /var/run are cleared, and MySQL hasn't recreated the socket
  • Works fine as one user but fails for another user with permission errors
  • Application container or service fails to start because it cannot connect to MySQL on startup
  • Intermittent failures during high system load or after disk space issues

Common causes

  1. MySQL server is not running or crashed—the socket file is never created without an active server process
  2. Socket file path configured in client differs from path where server creates it (my.cnf mismatch)
  3. Insufficient file permissions on the socket file directory (/var/run/mysqld/) preventing access
  4. Socket directory was deleted or cleaned up (common after system reboot if using /tmp/)
  5. Socket file deleted by cleanup tools or system maintenance processes
  6. MySQL data directory corrupted or inaccessible, preventing server startup and socket creation
  7. Disk full or inode exhaustion preventing socket file creation
  8. SELinux or AppArmor policies blocking socket file creation or access

How to fix "ERROR 2001: Can't create UNIX socket"

1Verify that MySQL server is running

ERROR 2001 cannot occur if the server is running and functioning. Check the server status first:

bash
# Check if MySQL service is running
sudo systemctl status mysql
# or
sudo service mysql status

# On macOS with Homebrew
brew services list | grep mysql

# Check if MySQL process exists
ps aux | grep mysqld

If the service is not running, start it:

bash
# Start MySQL
sudo systemctl start mysql
# or
sudo service mysql start

# On macOS
brew services start mysql

Wait a few seconds for MySQL to fully initialize and create the socket file.

2Find the actual socket file location

The client and server must agree on where the socket file is located. Find the current configuration:

bash
# Get the socket path from MySQL configuration
mysql_config --socket

# Or check the my.cnf file
cat /etc/mysql/my.cnf | grep socket
cat /etc/my.cnf | grep socket

# Check all my.cnf locations
grep -r "^socket" /etc/mysql/

Common socket locations:
- Linux: /var/run/mysqld/mysqld.sock or /tmp/mysql.sock
- macOS: /tmp/mysql.sock or /var/run/mysqld/mysqld.sock
- Docker: /var/run/mysqld/mysqld.sock (inside container)

Make note of the path—you'll need it for the next steps.

3Verify the socket file exists and check permissions

Once you know the socket path, verify the file exists and has correct permissions:

bash
# Check if socket file exists (replace path if different)
ls -la /var/run/mysqld/mysqld.sock

# If the file exists, check permissions
ls -la /var/run/mysqld/

The socket file should be owned by the mysql user and readable/writable:

bash
srwxrwxrwx mysql mysql /var/run/mysqld/mysqld.sock

If the file doesn't exist, the server either isn't running or its socket is at a different location. If permissions are wrong, proceed to the next step to fix them.

4Fix socket directory and file permissions

If the socket file exists but has incorrect permissions, or if the directory doesn't have proper permissions:

bash
# Ensure the socket directory exists with correct permissions
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo chmod 755 /var/run/mysqld

# If the socket file exists but has wrong permissions
sudo chmod 660 /var/run/mysqld/mysqld.sock
sudo chown mysql:mysql /var/run/mysqld/mysqld.sock

# Restart MySQL to recreate the socket with correct permissions
sudo systemctl restart mysql

# Verify the socket now has correct permissions
ls -la /var/run/mysqld/mysqld.sock

After restart, the socket should be owned by mysql:mysql with mode 660 (rw-rw----) or 777 (rwxrwxrwx).

5Match client and server socket paths (if they differ)

If the server is running but the client is looking in the wrong location, create a symbolic link or update configuration:

Option A: Create a symbolic link (quick fix)

bash
# If server socket is at /var/run/mysqld/mysqld.sock
# but client is looking at /tmp/mysql.sock
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

Option B: Update client configuration (/etc/mysql/my.cnf)

ini
[client]
socket=/var/run/mysqld/mysqld.sock

[mysqldump]
socket=/var/run/mysqld/mysqld.sock

[mysql]
socket=/var/run/mysqld/mysqld.sock

Option C: Specify socket on command line (temporary)

bash
mysql -u root -p --socket=/var/run/mysqld/mysqld.sock
mysqldump -u root -p --socket=/var/run/mysqld/mysqld.sock

After making configuration changes, test the connection:

bash
mysql -u root -p
6Check disk space and filesystem health

ERROR 2001 can also occur if the disk is full or has inode issues:

bash
# Check disk usage
df -h

# Check inode usage
df -i

# Look for /var or / filesystem at 100% or near capacity

If disk space is near full:

bash
# Free up space (remove old logs, temp files, etc.)
sudo rm -rf /var/log/*.log.*  # old log archives
sudo apt-get clean  # clear package cache

If inode count is exhausted, MySQL cannot create the socket file even if space is available. This requires more drastic cleanup—contact your system administrator.

After freeing space, restart MySQL:

bash
sudo systemctl restart mysql
7Check SELinux/AppArmor security policies (if enabled)

On systems with enhanced security (Red Hat, CentOS, Debian with AppArmor), policies may block socket creation:

For SELinux (Red Hat/CentOS):

bash
# Check if SELinux is enabled
getenforce

# Temporarily disable to test
sudo setenforce 0

# Try connecting to MySQL
mysql -u root -p

# If it works, SELinux is the issue. To fix permanently:
sudo semanage fcontext -a -t mysqld_var_run_t "/var/run/mysqld/mysqld.sock"
sudo restorecon -v /var/run/mysqld/mysqld.sock

# Re-enable SELinux
sudo setenforce 1

For AppArmor (Debian/Ubuntu):

bash
# Check AppArmor status
sudo aa-status

# Temporarily disable to test
sudo aa-complain /usr/sbin/mysqld

# Try connecting
mysql -u root -p

# If it works, enforce the complaining profile
sudo aa-enforce /usr/sbin/mysqld

If security policies are blocking access, edit the profile to allow socket access in /var/run/mysqld/.

Advanced notes

For Docker/Kubernetes deployments, ensure the MySQL container or pod has the socket directory mounted or created with correct permissions. In Kubernetes, use initContainers or livenessProbes with a delayed initialDelaySeconds since MySQL needs time to create the socket. For high-availability setups with multiple MySQL replicas, each instance creates its own socket—ensure connection strings specify the correct host and socket path. On systems with /tmp on a separate tmpfs partition, socket files in /tmp may not persist across reboots—prefer /var/run/mysqld/ instead. For debugging socket issues, enable MySQL error logging: add 'log-error=/var/log/mysql/error.log' to my.cnf and review the error log after restart. If MySQL is built from source, verify it was compiled with socket support (./configure --with-unix-socket-path=/var/run/mysqld/mysqld.sock). In containerized environments with systemd, ensure MountFlags is set appropriately in the MySQL systemd unit file.

Frequently asked questions

What does "2001" mean?
MySQL ERROR 2001 (CR_SOCKET_CREATE_ERROR) is a client-side connection error that occurs when the MySQL client attempts to establish a local connection via UNIX socket but fails to create or access the socket file. sock) that enable fast, permission-based local communication between the client and server. This error indicates one of three fundamental problems: (1) the MySQL server is not running, so the socket file doesn't exist, (2) the socket file exists but the client doesn't have permission to access it, or (3) the client is looking for the socket in the wrong location because of configuration mismatches.
How do I fix "2001"?
ERROR 2001 (CR_SOCKET_CREATE_ERROR) occurs when the MySQL client cannot create or access the UNIX socket file used for local connections. This typically happens when the socket file is missing, has incorrect permissions, or the server isn't running.
What causes "2001"?
MySQL server is not running or crashed—the socket file is never created without an active server process Socket file path configured in client differs from path where server creates it (my.cnf mismatch) Insufficient file permissions on the socket file directory (/var/run/mysqld/) preventing access
Is the "2001" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading