error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock
To find all socket files on your system run:
sudo find / -type s
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:
socket=/var/lib/mysql/mysql.sock
Sometimes the system startup script that launched the command line executable specifies a flag --socket=path
. This flag could override the my.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.
Then, stop the mysqld process. How you do this will vary by system.
If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:
service mysqld stop
/etc/init.d/mysqld stop
mysqladmin -u root -p shutdown
- Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either:
- One step:
pkill -9 mysqld
- Two step (least preferred):
- Find the process id of mysql with either
pgrep mysql
orps aux | grep mysql | grep -v grep
- Assuming the process id is
4969
terminate withkill -9 4969
- Find the process id of mysql with either
- One step:
After you do this you might want to look for a pid file in /var/run/mysqld/
and delete it
Make 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.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Are you connecting to "localhost" or "127.0.0.1" ? I noticed that when you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used. You could try using "127.0.0.1" if the socket connector is not enabled/working.
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in ubuntu 14.04
you could try starting your mysql first
> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
>
> service mysql start or service mysql start
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in Ubuntu 12.04.5 LTS
Here is what fixed for me with Mariadb
First find out if your mysql config file ,most likely located at /etc/mysql/my.cnf
or /etc/my.cnf
has the correct mysql.sock entry or not
You can find out where mysql.sock file is located by running find / -type s
, if the entry is not correct in your mysql config, file fix it , also make sure mysql.pid has the correct path as well.
Now try to start mysql server , if it starts fine and you can see all DB's and tables within , you are good and dont need to follow rest of the post .
If mysql fails to start after fixing mysql.sock path , read on
Add the following to your my.cnf file ,
innodb_force_recovery = 1
inside the mysqld
block , and restart mysql.
If it fails to start , increment the number by one each time , but keep in mind , after 3 , their might be some data loss (not happened to me , but i have only read about anything above 3 being a salvaging measure , than a recovery)
Dont panic if some of the tables you previously had , stop showing that they dont exist in the engine . Ones mysql starts successfully (if you dont have a backup yet , better make one now , just in case things go south from here on) , remove innodb_force_recovery = 1
from my.cnf file and restart mysql again , all your tables should be available again.
Posts that helped me
- https://stackoverflow.com/a/20617180/3117013
- https://stackoverflow.com/a/11990813/3117013
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock
To find all socket files on your system run:
sudo find / -type s
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:
socket=/var/lib/mysql/mysql.sock
Sometimes the system startup script that launched the command line executable specifies a flag --socket=path
. This flag could override the my.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.
Then, stop the mysqld process. How you do this will vary by system.
If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:
service mysqld stop
/etc/init.d/mysqld stop
mysqladmin -u root -p shutdown
- Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either:
- One step:
pkill -9 mysqld
- Two step (least preferred):
- Find the process id of mysql with either
pgrep mysql
orps aux | grep mysql | grep -v grep
- Assuming the process id is
4969
terminate withkill -9 4969
- Find the process id of mysql with either
- One step:
After you do this you might want to look for a pid file in /var/run/mysqld/
and delete it
Make 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.
Can't find mysqld.sock: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 No such file or directory)
I got it!
So, first I removed every trace of MariaDB with these commands:
sudo service mysql stop
sudo apt-get --purge remove "mysql*
sudo rm -rf /etc/mysql/
Then I reinstalled it:
apt-get update
apt-get upgrade
apt-get install mariadb-server
Now mariaDB works. However I still have problems with xampp because his Mysql database has a conflict with my mariaDB. So I changed the Xampp Mysql port from 3306 to 3308 and all works fine.
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with:
socket=/var/lib/mysql/mysql.sock
You can check if mysql is running with the following command:
mysqladmin -u root -p status
Try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/lib/mysql/
That solved it for me.
Related Topics
SQL Split Values to Multiple Rows
How to Create a Parameterized SQL Query? Why Should I
MySQL Select 10 Random Rows from 600K Rows Fast
Insert into ... Values ( Select ... from ... )
How to Filter SQL Results in a Has-Many-Through Relation
How to Create Id With Auto_Increment on Oracle
SQL Join and Different Types of Joins
Return Row Only If Value Doesn't Exist
How Can Prepared Statements Protect from SQL Injection Attacks
How to Query Mongodb With "Like"
Count(*) VS Count(1) - SQL Server
Get Records With Max Value For Each Group of Grouped SQL Results
How to Escape a Single Quote in SQL Server
Difference Between Lateral Join and a Subquery in Postgresql