Cannot find mysql.sock

MysqlMacosSocketsInstallation

Mysql Problem Overview


I just had to re-install mysql and I am having a problem starting it up. It cannot find the socket (mysql.sock). The problem is that neither can I. In my Mac OS X 10.4 terminal, I type: locate mysql.sock, and I get back /private/tmp/mysql.sock. It makes sense that the socket file exist in that location, but it actually does not.

  1. How can I find the socket file?

  2. If locate is returning a false location, it must have some sort of memory and probably indexes. How can I refresh that index?

Mysql Solutions


Solution 1 - Mysql

to answer the first part of your question:

run

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

and check the 'socket' variable

Solution 2 - Mysql

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 - Mysql

This found it for me:

netstat -ln | grep mysql

Mac OSX

Solution 4 - Mysql

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 - Mysql

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

Solution 6 - Mysql

I got the exact path using:

netstat -ln | grep -o -m 1 -E '\S*mysqld?\.sock'

Since this only returns the path and doesn't require any input you could potentially use it in a shell script.

MySQL must be currently running on your machine for this to work. Works for MariaDB too.

Solution 7 - Mysql

The original questions seems to come from confusion about a) where is the file, and b) where is it being looked for (and why can't we find it there when we do a locate or grep). I think Alnitak's point was that you want to find where it was linked to - but grep will not show you a link, right? The file doesn't live there, since it's a link it is just a pointer. You still need to know where to put the link.

my sock file is definitely in /tmp and the ERROR I am getting is looking for it in /var/lib/ (not just /var) I have linked to /var and /var/lib now, and I still am getting the error "Cannot connect to local MySQL server through socket 'var/lib/mysql.sock' (2)".

Note the (2) after the error.... I found on another thread that this means the socket might be indeed attempted to be used, but something is wrong with the socket itself - so to shut down the machine - completely - so that the socket closes. Then a restart should fix it. I tried this, but it didn't work for me (now I question if I restarted too quickly? really?) Maybe it will be a solution for someone else.

Solution 8 - Mysql

$ mysqladmin variables | grep sock

Try this instead, this will output the demanded result, getting rid of unrelated info.

Solution 9 - Mysql

I'm getting the same error on Mac OS X 10.11.6:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

After a lot of agonizing and digging through advice here and in related questions, none of which seemed to fix the problem, I went back and deleted the installed folders, and just did brew install mysql.

Still getting the same error with most commands, but this works:

/usr/local/bin/mysqld

and returns:

> /usr/local/bin/mysqld: ready for connections. > >Version: '5.7.12' socket: '/tmp/mysql.sock' port: 3306 Homebrew

Solution 10 - Mysql

To refresh the locate's database I ran

/usr/libexec/locate.updatedb

Solution 11 - Mysql

I couldn't find mysql socket at all so reinstalled mysql server(all tables and phpmyadmin settings were preserved). Here are the commands:

  1. Install

> sudo apt-get install mysql-server

  1. Follow terminal configuration steps > sudo mysql_secure_installation

  2. Check status: (Should return "Active: active (running)") > systemctl status mysql.service

Solution 12 - Mysql

Unfortunately none of the above have worked in my case. But finally I found solutions.

To find where is mysql.sock file, simply open xampp manager, select MySQL and click on Configure on the right. On the config panel click Open Conf File, and simply search for mysql.sock by pressing the CMD+F shortcut.

In my case, the owner of the mysql.sock was changed, and I had to change it back to root admin with: chmod root:admin mysql.sock

After that the database had been accessed.

Solution 13 - Mysql

I can't help with question #1, but to refresh locate's file database, run:

updatedb

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTonyView Question on Stackoverflow
Solution 1 - MysqlbehasView Answer on Stackoverflow
Solution 2 - MysqlEugene RamirezView Answer on Stackoverflow
Solution 3 - Mysqlzero_coolView Answer on Stackoverflow
Solution 4 - MysqlAlnitakView Answer on Stackoverflow
Solution 5 - MysqlMatthias D.View Answer on Stackoverflow
Solution 6 - Mysqlmattbell87View Answer on Stackoverflow
Solution 7 - MysqlAmy DView Answer on Stackoverflow
Solution 8 - MysqlsoarinblueView Answer on Stackoverflow
Solution 9 - MysqlszeitlinView Answer on Stackoverflow
Solution 10 - MysqlTimbinousView Answer on Stackoverflow
Solution 11 - MysqlNika TsogiaidzeView Answer on Stackoverflow
Solution 12 - Mysqlszatti1489View Answer on Stackoverflow
Solution 13 - MysqlChad BirchView Answer on Stackoverflow