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.
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.
ERROR 2001 cannot occur if the server is running and functioning. Check the server status first:
# 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 mysqldIf the service is not running, start it:
# Start MySQL
sudo systemctl start mysql
# or
sudo service mysql start
# On macOS
brew services start mysqlWait a few seconds for MySQL to fully initialize and create the socket file.
The client and server must agree on where the socket file is located. Find the current configuration:
# 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.
Once you know the socket path, verify the file exists and has correct permissions:
# 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:
srwxrwxrwx mysql mysql /var/run/mysqld/mysqld.sockIf 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.
If the socket file exists but has incorrect permissions, or if the directory doesn't have proper permissions:
# 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.sockAfter restart, the socket should be owned by mysql:mysql with mode 660 (rw-rw----) or 777 (rwxrwxrwx).
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)
# 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.sockOption B: Update client configuration (/etc/mysql/my.cnf)
[client]
socket=/var/run/mysqld/mysqld.sock
[mysqldump]
socket=/var/run/mysqld/mysqld.sock
[mysql]
socket=/var/run/mysqld/mysqld.sockOption C: Specify socket on command line (temporary)
mysql -u root -p --socket=/var/run/mysqld/mysqld.sock
mysqldump -u root -p --socket=/var/run/mysqld/mysqld.sockAfter making configuration changes, test the connection:
mysql -u root -pERROR 2001 can also occur if the disk is full or has inode issues:
# Check disk usage
df -h
# Check inode usage
df -i
# Look for /var or / filesystem at 100% or near capacityIf disk space is near full:
# Free up space (remove old logs, temp files, etc.)
sudo rm -rf /var/log/*.log.* # old log archives
sudo apt-get clean # clear package cacheIf 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:
sudo systemctl restart mysqlOn systems with enhanced security (Red Hat, CentOS, Debian with AppArmor), policies may block socket creation:
For SELinux (Red Hat/CentOS):
# 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 1For AppArmor (Debian/Ubuntu):
# 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/mysqldIf security policies are blocking access, edit the profile to allow socket access in /var/run/mysqld/.
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.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL