Error
Error Code:
2001
MySQL Error 2001: UNIX Socket Creation Failed
Description
Error 2001 indicates that MySQL or a client application failed to create a UNIX domain socket. This socket is crucial for local communication between MySQL processes or between a client and the MySQL server when connecting via the local filesystem. It typically occurs due to permission issues, a missing directory, or full disk space in the intended socket location.
Error Message
Can't create UNIX socket (%d)
Known Causes
4 known causesInsufficient Directory Permissions
The user account attempting to create the UNIX socket lacks the necessary write permissions for the target directory (e.g., /tmp, /var/run/mysqld).
Socket Directory Missing
The directory path specified in the MySQL configuration (my.cnf) or by the client for the UNIX socket file does not exist on the filesystem.
Filesystem Capacity Reached
The disk partition where the UNIX socket is intended to be created is full, or the maximum number of inodes has been exhausted.
Misconfigured Socket Path
The `socket` parameter in the MySQL configuration file (my.cnf) or the client's connection string points to an incorrect or invalid location.
Solutions
3 solutions available1. Verify and Adjust Socket File Permissions easy
Ensures the MySQL user has write permissions to the directory where the socket file is created.
1
Locate the MySQL configuration file (my.cnf or my.ini). Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or `/etc/mysql/mysql.conf.d/mysqld.cnf` on Linux, and `my.ini` within the MySQL installation directory on Windows.
2
Find the `socket` directive within the `[mysqld]` section to determine the socket file path. If it's not specified, MySQL usually defaults to `/tmp/mysql.sock` or `/var/run/mysqld/mysqld.sock`.
[mysqld]
socket = /var/run/mysqld/mysqld.sock
3
Check the permissions of the directory containing the socket file using `ls -ld <directory_path>`. For example, if the socket is in `/var/run/mysqld/`:
ls -ld /var/run/mysqld/
4
If the MySQL user (e.g., `mysql`) does not have write permissions to this directory, grant them. You might need to use `sudo`.
sudo chown -R mysql:mysql /var/run/mysqld/
sudo chmod 755 /var/run/mysqld/
5
Restart the MySQL service.
sudo systemctl restart mysql
2. Relocate the MySQL Socket File medium
Changes the socket file location to a directory with appropriate permissions.
1
Edit the MySQL configuration file (`my.cnf` or `my.ini`).
2
In the `[mysqld]` section, change the `socket` directive to a more suitable location, such as a dedicated directory for MySQL sockets. For example:
[mysqld]
socket = /var/lib/mysql/mysql.sock
3
Create the new directory if it doesn't exist and ensure the MySQL user has ownership and write permissions.
sudo mkdir -p /var/lib/mysql/
sudo chown mysql:mysql /var/lib/mysql/
sudo chmod 755 /var/lib/mysql/
4
If you are moving the socket from a default location like `/tmp`, ensure that other applications or services that rely on the old socket path are updated to use the new path. This might involve updating client configurations or application connection strings.
5
Restart the MySQL service.
sudo systemctl restart mysql
3. Ensure MySQL Daemon is Running and Accessible easy
Confirms the MySQL server process is active and not blocked by firewall or SELinux.
1
Check if the MySQL service is running.
sudo systemctl status mysql
2
If it's not running, attempt to start it.
sudo systemctl start mysql
3
Check system logs for any other errors related to MySQL startup or socket creation. Common log locations are `/var/log/mysql/error.log` or `/var/log/syslog`.
sudo tail -f /var/log/mysql/error.log
4
If SELinux is enabled, it might be preventing socket creation. Check SELinux audit logs (`/var/log/audit/audit.log`) for denials related to MySQL or socket files. Temporarily set SELinux to permissive mode to test if it's the cause:
sudo setenforce 0
5
If SELinux is the culprit, re-enable it (`sudo setenforce 1`) and then adjust SELinux policies to allow MySQL to create its socket. This often involves using `audit2allow` to generate custom policies.
sudo ausearch -c 'mysqld' --raw | audit2allow -M my-mysqld
sudo semodule -i my-mysqld.pp
6
Ensure no firewall rules are blocking access to the MySQL socket (though this is less common for local socket connections, it's worth considering if the error occurs in specific scenarios).