The file mysqld.sock is removed and recreated constantly - mysql

This error appears to me:
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/var/run/mysqld/mysqld.sock' (2)
I saw in others threads and no one help me, because it is created but in seconds is removed and recreated again...
Any idea?

That is not the error, it is a symptom.
Your mysql-server is dieing and restarting again probably from some error in configuration, or permissions in your system.
You should start by looking your syslog either /var/log/syslog or /var/log/messages to see what is happening with your mysqlserver when it starts.
If you don't see anything you can try starting mysqld from your root-shell and see what it sends to stdout/err.

Related

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

Out of the sudden, I am getting this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
on mysql when I run mysql -uroot.
I haven't touched web dev for around 1 month and as soon as I wanted to return to my project, I am getting this very annoying error out of nowhere. I have trie all advice and solutions from other answers and none of them work. This includes changing permissions to 777, ownership to root, mysql etc, killing PID all of those and none of them work. I even tried re-installing mysql and still getting the same error. I even re-installed my whole macOS Mojave and still getting the same error. I mean this error doesn't even make sense...
Is mysql completely broken or I am just super dumb?
Has anyone had this issue? If so how did you solve it?
The error says, it's using the socket /tmp/mysql.sock and failed.
Try to troubleshoot with the below things.
check the process status of mysqld and confirm its running or not. If running which socket is using.
ps -ef | grep -i mysqld
Based on the socket file try login to the MySQL through command line.
mysql -uroot -p -S <<file.sock>>
Check the my.cnf to make sure which socket file its mentioned under the [client] group option.
In your case, probably the mysql instance reading the socket from my.cnf files where it placed somewhere. Check the hierarchy of the configuration file usage by mysqld which may be located in either the /etc or /etc/mysql

Mysql error 2002 after server shutdown

The server had shut down yesterday because electricity had cut off. After that, I've tried connect to Mysql but only got the 2002 error related with mysql.sock. Anyway, I've fixed the issue with this solution:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
sudo chmod -R 755 /var/lib/mysql/
But my question is: Why? Why a shutdown caused this error? How prevent this from happening again?
Check the '/var/log/mysqld.log' first to see messages on file/directory permission
If the MySQL server terminated unexpectedly, the MySQL socket was not reset after the reboot
Due to power shutdown, the existing mysql process got terminated and socket file is not removed properly as this is not a graceful shutdown. The MySQL server no longer attempts to verify the existence of a MySQL socket when the socket is not being used by any processes as the block checking for socket existence should only matter if there's a PID attached to the other end of the socket. On unclean reboot, this socket will persist and thus cause the failure.
Solution :
I guess the simplest thing to do is remove the socket check. If there's no mysqld pids, then the existence of the socket may not be a useful check
Why a shutdown caused this error?
The error indicates that MySQL was not bound to its socket. It probably wasn't able to bind to its socket because it appeared that another process (namely the MySQL instance that did not shutdown cleanly) was still bound thereto.
How prevent this from happening again?
Install a UPS (uninterruptible power supply), which can provide backup power (from batteries) whilst signalling to the server that primary power has failed. This gives the server an opportunity to cleanly shutdown, so that its files are not left in a corrupt state.

Starting MySql after migration Yosemite

I've run into a problem here, and I'm not sure what to do. I migrated a Yosemite Mac to a new Mac Pro. Apache turns on, but MySql does not with this error: The operation couldn’t be completed. (XAMPPErrorDomain error 1.)
I didn't know if I need to reinstall MySql or upgrade it, or what this error means. I created the plist file as in the example and ran permissions, but that did not change the outcome. Going to websites in localhost, WordPress shows an error establishing db connection.
I went to Github to install MySql and it went fine, but it does not work with Xampp and Desktop Server. I chose to NOT start MySql when I rebooted, but apparently the Github version started anyway (and I cannot find a way to turn it off!) Now when I try to start MySql from Xampp, it says another version is already running.
Any help appreciated.
When I ask for version number in terminal I get this response:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
HOWEVER, when I went to /var/ and temp I found an alias for mysql.sock, BUT it was not connected to an original file... Now that file does not exist anywhere on my computer.
Open /Applications/XAMPP/xamppfiles/xampp and add this line somewhere at the top:
unset DYLD_LIBRARY_PATH
I found that what was required was a complete uninstall of MySql following this procedure: http://bytearrays.com/completely-uninstall-mysql-mac-osx/
And then a reinstall. ServerPress.com was very helpful in diagnosing the problems.

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

I just installed mySQL and when I try to type mysql in my mac terminal I'm getting
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I tried searching for an answer but I'm still stuck. Also, I don't know if this is relevant or connected, but when I go to my preference panel to try to start mySQL it doesn't start. On some sites such as other stackoverflow pages, it says to try running "/usr/local/mysql/bin/mysqld_safe" but for me it just permission denied..
I tried to do ps -u mysql to check if it's running and it printed out and an address: usr/local/mysql/bin/mysqld --basedir=/usr/local. So I assume it's running? Even though I can't physically press the button and enable it in the preference panel which is weird.
EDIT: I typed
$ sudo /usr/local/mysql/bin/mysqld_safe
Password:
130930 11:55:15 mysqld_safe Logging to '/usr/local/mysql/data/myname-mac.att.net.err'.
130930 11:55:15 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
130930 11:55:18 mysqld_safe mysqld from pid file /usr/local/mysql/data/myname-mac.att.net.pid ended
why did it end right there?
I had this same error message for days and finally figured it out.
I had somehow gotten a my.cnf file on my computer from AMPS or possibly another MYSQL install (that I believed I had deleted).
But it turns out it was a hidden file in /etc/ that I had to manually delete. http://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/
Finally, I installed MySQL with homebrew one more time –– and success! It works. Also of course this time I spot a message in the homebrew setup process that points out the problem I was having:
A "/etc/my.cnf" from another install may interfere with a
Homebrew-built server starting up correctly.
Hope this helps.
I also experienced a similar error. After trying all prescribed solutions like in this related post, noticed that it was a simple solution: first make sure the mysql daemon is running. For example, on a Homebrew installation (macOS), start mysql with: brew services start mysql

missing mysql.sock after new install

I recently upgraded to a new macbook pro and haven't been able to get mysql to install. I have been trying to install using the:
mysql-5.5.8-osx10.6-x86_64.dmg
which 'should' work for my machine, but is not. After installing the three pieces (mysql.pkg,
startup.pkg, prefpane) I get nothing. Trying to start mySQL through the prefpane freezes sysprefs. Trying to start via the terminal gets this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
So I deleted all of the mysql install files and reinstalled following these instructions:
https://discussions.apple.com/message/12820394
when I get to the step where I would set up the root password i get the following error:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
This is perhaps due to the fact that there are no mysql related files in /tmp ? I can't find anything *.sock anywhere on my machine at all. I really don't know much about server admin, so I could be totally confused and off here.
It can have moved to /var/mysql/mysql.sock. I think it is the new position. You may need to point your php.ini to that or create a symbolic link to ln -s /var/mysql/mysql.sock /tmp/mysql.sock...