[2002] Causes and remedies for MySQL socket errors
Hello. My name is Goto from the Web Systems Division.
When connecting to MySQL server from MySQL client software (mysql, PHP, Perl, etc.),
- socket '/tmp/mysql.sock '
- No such file or directory (trying to connect via unix : ///tmp/mysql . sock)
You may be unable to connect due to an error like this.
This means
"Unable to connect to local MySQL server through socket /tmp/mysql.sock." (I just translated it)
A socket is a Unix domain socket (file system socket), and when communicating within the local system,
communication is performed between the server and client through input and output of this file.
It's an intermediary role.
Now, I would like to explain the causes of such errors and how to deal with them.
Cause 1. MySQL server is not started
$ ps aux | grep mysqld
Check if the process exists.
If not, start it.
$ sudo /etc/init.d/mysqld status
Cause 2. The paths of the Unix socket used by the MySQL server and the Unix socket used by the client software are different.
No such file or directory (trying to connect via unix:///tmp/mysql.sock)
For example, the above error shows that the client is referring to /tmp/mysql.sock, but
the MySQL server is referring to /var/lib/mysql/mysql.sock.
There are two solutions in this case.
Solution A. Align clients
Referring to the MySQL configuration file, /etc/my.cnf,
[mysqld] socket=/var/lib/mysql/mysql.sock
Since the path is written like this, all you need to do is set the socket of the client software to the same path.
Solution B. Match MySQL
Let's rewrite /etc/my.cnf as shown below.
[mysqld] socket=same socket path as client [client] soket=same socket path as client [shell] After rewriting, restart MySQL. [shell]$ sudo /etc/init.d/mysqld restart
Cause 3. There is no socket file in the first place.
There are two ways to solve this too.
Solution A. Restart the MySQL server and it will be restored.
(*Restart the server, not mysql.)
$ sudo shutdown -r now
Solution B. Create a socket file
After checking /etc/my.cnf and checking the path,
$ touch /path/mysql.sock $ chown mysql:mysql /path/mysql.sock
Create a socket at that path and restart MySQL.
$ sudo /etc/init.d/mysql restart
These are the causes and solutions for MySQL 2002 errors.