Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Does anyone know why my /var/run/mysqld/mysqld.sock socket file would not be on my computer when I install (or reinstall) MySQL 5.1?

Right now, when I try to start up a server with mysqld, I get errors like Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect, but creating a blank file with that name (as suggested on the ubuntu forums) was unsuccessful.

I had both mysql and postgres serving fine until I upgraded to natty a little while ago; I have spent hours walking through both databases trying to figure out what is going on. I can give up on postgres, but I cannot work without a working copy of mysql.

The weirdest part: I use Kubuntu, and my understanding is that KDE uses mysql to store user permissions, etc. I am not experiencing any weird permissions issues; can I take this to mean that (somehow?) MySQL is actually working?

Maybe these socket files live in a different place in natty? Would it be easier to just reinstall the os fresh? At this point, I am open to any suggestions that will stop wasting my time.

share|improve this question

migrated from stackoverflow.com Jun 10 '11 at 23:37

This question came from our site for professional and enthusiast programmers.

    
You need to start mysql server first and then that file /var/run/mysqld/mysqld.sock will be created. As what @Paul said, you have to remove any file you put in that location. –  Evan Dec 10 '14 at 13:13

6 Answers 6

up vote 7 down vote accepted

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.

share|improve this answer
    
Thanks for the explanation of socket files, and sorry about the poorly-worded question: my original issue was that the socket file was missing - the error mysql kept throwing was Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect –  egbutter Jun 11 '11 at 4:09
    
but how is it created? because I still dont have it.. :-s any idea? –  jpganz18 Jan 31 '13 at 2:41
    
You probably have a mysql client that expects the socket to be in that location, but the server doesn't create it there (or the server isn't running) If the server is running, look in /tmp or use find or locate to find the socket file, then start mysql client with -S <path to socket file> –  sed_and_done Jan 8 at 15:40

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
share|improve this answer

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
share|improve this answer
    
This is actually a brilliant (and much needed) answer because, historically speaking, I have seen the mysql.sock disappear for no good reason in every version of MySQL I have worked with (back to 4.0). When this happens, I login just like this but I use --protocol=tcp instead of --port. When you shutdown mysql, the service looks for the socket file. Thus, running service mysql stop would fail. To get around the missing socket file headache, I run mysqladmin -h127.0.0.1 --protocol=tcp -uroot -p shutdown. Oh, BTW, +1 !!! –  RolandoMySQLDBA Feb 13 '13 at 18:54
    
Thank you. This was my first answer anywhere online :) And yes. Alternative method to use TCP is by specifying --protocol=tcp. –  sccott Feb 21 '13 at 21:04

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.

share|improve this answer

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
share|improve this answer

If you are using nginx php-fastcgi and you got 502 Bad Gateway error than you have to look at your virtual host configuration on nginx config file. You have to set or correct the fastcgi_pass parameter.The fastcgi_pass is the variable to set the socket connection between nginx and php CGI.

Another point of issue is that the binary starter script could missed the following entries(important) open with: nano /usr/bin/php-fastcgi

SOCKET=/var/run/php-fastcgi/php-fastcgi.socket
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid

The complete content of my starter script /usr/bin/php-fastcgi:

#!/bin/bash

FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi/php-fastcgi.socket
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=6
PHP5=/usr/bin/php5-cgi

/usr/bin/spawn-fcgi -s $SOCKET -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.