Reputation: 19151
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.
How can I find the socket file?
If locate is returning a false location, it must have some sort of memory and probably indexes. How can I refresh that index?
Upvotes: 94
Views: 155105
Reputation: 3476
to answer the first part of your question:
run
% mysqladmin -p -u <user-name> variables
and check the 'socket' variable
Upvotes: 150
Reputation: 362
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.
Upvotes: 0
Reputation: 1097
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
2) Follow terminal configuration steps
sudo mysql_secure_installation
3) Check status: (Should return "Active: active (running)")
systemctl status mysql.service
Upvotes: 1
Reputation: 3123
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.
Upvotes: 65
Reputation: 3341
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
Upvotes: 1
Reputation: 575
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.
Upvotes: 7
Reputation: 1687
$ mysqladmin variables | grep sock
Try this instead, this will output the demanded result, getting rid of unrelated info.
Upvotes: 2
Reputation: 29
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.
Upvotes: 2
Reputation: 121
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= ...
Upvotes: 12
Reputation: 2983
To refresh the locate's database I ran
/usr/libexec/locate.updatedb
Upvotes: 0
Reputation: 339816
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
Upvotes: 21
Reputation: 74528
I can't help with question #1, but to refresh locate
's file database, run:
updatedb
Upvotes: -4