Solution 1:

to answer the first part of your question:

run

% mysqladmin -p -u <user-name> variables

and check the 'socket' variable

Solution 2:

This solved my problem

mysql_config --socket

UPDATE

mysql_config can tell us where the file mysql.sock should be, but in my case the file didn't exist. So, I've deleted my.cnf:

sudo rm -rf /etc/my.cnf

And then restarted mysql:

brew services restart mysql

The file was created and mysql is now running well.

Solution 3:

This found it for me:

netstat -ln | grep mysql

Mac OSX

Solution 4:

The socket file should be created automatically when the MySQL daemon starts.

If it isn't found, most likely the directory which is supposed to contain it doesn't exist, or some other file system problem is preventing the socket from being created.

To find out where the file should be, use:

% mysqld --verbose --help | grep ^socket

Solution 5:

My problem was also the mysql.sock-file.

During the drupal installation process, i had to say which database i want to use but my database wasn't found

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

the system is searching mysql.sock but it's in the wrong directory

all you have to do is to link it ;)

it took me a lot of time to google all important informations but it took me even hours to find out how to adapt , but now i can present the result :D

ps: if you want to be exactly you have to link your /tmp/mysql.sock-file (if it is located in your system there too) to the directory given by the php.ini (or php.default.ini) where pdo_mysql.default_socket= ...