[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[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.

If you found this article helpful , please give it a like!
4
Loading...
4 votes, average: 1.00 / 14
55,193
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author