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 MySQL server error 111
It probably means that your MySQL server is only listening the localhost interface.
If you have lines like this :
bind-address = 127.0.0.1
In your my.cnf
configuration file, you should comment them (add a # at the beginning of the lines), and restart MySQL.
sudo service mysql restart
Of course, to do this, you must be the administrator of the server.
Related Topics
Sql Parentheses Use in an or Clause
How to Use T-SQL Full-Text Search to Get Results Like Google
How to Use a Case Statement in Scalar Valued Function in Sql
Using SQL Query to Determine If a Table Exists
Does "Select for Update" Prevent Other Connections Inserting When the Row Is Not Present
Oracle 11G - How to Optimize Slow Parallel Insert Select
Entity Framework Entity SQL Vs Linq to Entities
Custom Sorting in SQL Order by Clause
Duplicate Postgresql Schema Including Sequences
Field Value Must Be Unique Unless It Is Null
Optimising a Select Query That Runs Slow on Oracle Which Runs Quickly on SQL Server
Using Sqldf and Rpostgresql Together
Frequent Error in Oracle Ora-04068: Existing State of Packages Has Been Discarded
Extract Time Part from Timestamp Column in Oracle
Sql-Style Group by Aggregate Functions in Jq (Count, Sum and etc)
Help Me Put Oracle Terminology into SQL Server Terminology
Select All Parents or Children in Same Table Relation SQL Server