What should mysqld.sock contain, why don't I have it?

Solution 1:

A socket file doesnt actually contain data, it transports it.. It is a special, unusual type of file created with special system calls/commands. It is not an ordinary file.

It is like a pipe the server and the clients can use to connect and exchange requests and data. Also, it is only used locally. Its significance is merely as an agreed rendezvous location in the filesystem.

Creating a plain old file and putting it in that location may actually interfere with the server creating it... and thereby prevent local clients from connecting to the server.

My recommendation is to remove any file you put in the location. The special socket file is created by the server.

Solution 2:

When you specify host=localhost, mysql client will try to login to mysql server using unix named pipe which requires a .sock file.

This can be bypassed by specifying host=127.0.0.1. This will make mysql client use TCP to connect to the server.

Taken from MySQL's documentation:

mysql --host=127.0.0.1 --port=3306 --user=your_uname --password=your_pass

Solution 3:

A socket is a special pseudo-file used for data transmission by reading and writing, not data storage.

The socket file is created when the service is started and removed when the service is terminated. The location of the file is defined in /etc/my.cnf like so:

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

Solution 4:

In my case, running mysqld_safe created a new mysqld.sock file.

$ cd /etc/init.d/
$ mysqld_safe

You'll probably won't get prompt back, but if you restart your session, a mysqld.sock file will be somewhere. Find it with

$ sudo find / -type s | grep mysqld.sock

Solution 5:

I had the same problem with the missing mysqld.sock. I went to the directory that contained mysql, namely /usr/bin in my case. Then I issued the command

mysql mysql --host=localhost --password=whatever --port=3306

The double mysql is not a typo but rather mysql is a database that will always be there in a new MySQL installation. I do not know if --host, --password or --port are needed but since it worked for me using these parameters I am including them. Once MySQL came up I went into the user table as set the password for root. Once MySQL came up the missing socket file was created. I hope this helps someone since I struggled for days.