After I rebooted my server, everything started up normally except for "mysql", i tried to start it up manually "/etc/init.d/mysql restart
" or with "service mysql restart
", it fails
In log file it says:
Jul 16 08:13:38 localhost /etc/init.d/mysql[18136]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Jul 16 08:13:38 localhost /etc/init.d/mysql[18136]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
I checked that path, but i didn't find that socket file, please advise?
To find all socket files on your system run:
My Mysql server system had the socket open at
/var/lib/mysql/mysql.sock
Once you find where the socket is being opened, add or edit the line to your
/etc/my.cnf
file with the path to the socket file:Sometimes the system startup script that launched the command line executable specifies a flag
--socket=path
. This flag could override themy.cnf
location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.If you're super user in the Linux system, based on the above just do this:
or sometimes you can do this:
After you do this you might want to look for a pid file in
/var/run/mysqld/
and delete itMake sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:
chmod 777 '/var/run/mysqld/mysqld.sock'
If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.
Also, the directory the socket resides in has to be reachable by the user running the mysqld process.
Reference : https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq
I tried to startup mysql in "Safe Mode" to create the sock file and pid file, but it fails for some error "bind",
yes, as said above locate your socket file first
#find / -type s
, if you found a mysqld.sock file under /var/run/mysqld/ directory, check whether any instances of mysqld running or not#netstat -anpt | grep 3306 or #ps aux | grep mysqld
if you found any running process stop it (#kill -9 pid) and remove the socket file. Then try to restart it and if mysql not creating socket file then try to start it likeAlso check your my.cnf file (/etc/mysql/my.cnf) and comment the bind-address field, and if you found any skip-network field comment it.
I had a similar problem when I restarted my laptop (Ubuntu 20.04 LTS) there is failure in the start of MySQL. All I know is mysqld.sock is missing.
To find all socket file in a system do
and check if there is mysqld.sock file. If there is mysqld.sock elsewhere then read the solution here.
If there is no mysqld.sock file anywhere then follow along.
mysql by default has mysqld.sock in '/var/run/mysqld/'. If you can't find mysqld.sock anywhere then, check for mysqld directory in '/var/run/'. For me mysqld directory is missing. To get it back, open terminal and do
After that
mysqld
folder should be back at/var/run/
.mysqld.sock
file is insidemysqld
folder. Check the status withsudo service mysql status
.