ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
MysqlUbuntuMysql Problem Overview
I'm getting this error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
even though I have managed to start mysql via command line in ubuntu
mysql stop/waiting
mysql start/running, process 17691
However when attempting to access the site I get a database connection error as well as the above error when trying to access mysql via mysql -u root -p
I checked my error logs and I saw this
131029 12:53:34 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
131029 12:53:34 [Note] Plugin 'FEDERATED' is disabled.
131029 12:53:34 InnoDB: The InnoDB memory heap is disabled
131029 12:53:34 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131029 12:53:34 InnoDB: Compressed tables use zlib 1.2.3.4
131029 12:53:34 InnoDB: Initializing buffer pool, size = 26.0G
131029 12:53:36 InnoDB: Completed initialization of buffer pool
131029 12:53:36 InnoDB: highest supported file format is Barracuda.
131029 12:53:38 InnoDB: Waiting for the background threads to start
131029 12:53:39 InnoDB: 5.5.34 started; log sequence number 5146431500
131029 12:53:39 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
131029 12:53:39 [Note] - '0.0.0.0' resolves to '0.0.0.0';
131029 12:53:39 [Note] Server socket created on IP: '0.0.0.0'.
131029 12:53:39 [Note] Event Scheduler: Loaded 0 events
131029 12:53:39 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.34-0ubuntu0.12.04.1-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
It's the first time I see this error and I'm not sure how to solve this issue, please help me out a bit here.
Thanks
UPDATE
Okay I tried glglgl's solution and after a restart, I get the following in the error log:
131029 13:17:36 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
131029 13:17:36 [Note] Plugin 'FEDERATED' is disabled.
131029 13:17:36 InnoDB: The InnoDB memory heap is disabled
131029 13:17:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131029 13:17:36 InnoDB: Compressed tables use zlib 1.2.3.4
131029 13:17:36 InnoDB: Initializing buffer pool, size = 26.0G
131029 13:17:38 InnoDB: Completed initialization of buffer pool
131029 13:17:38 InnoDB: highest supported file format is Barracuda.
131029 13:17:40 InnoDB: Waiting for the background threads to start
131029 13:17:41 InnoDB: 5.5.34 started; log sequence number 5146431500
131029 13:17:41 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
131029 13:17:41 [Note] - '127.0.0.1' resolves to '127.0.0.1';
131029 13:17:41 [Note] Server socket created on IP: '127.0.0.1'.
131029 13:17:41 [Note] Event Scheduler: Loaded 0 events
131029 13:17:41 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.34-0ubuntu0.12.04.1-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
Mysql Solutions
Solution 1 - Mysql
My problem was solved checking if the process was running on Ubuntu 12.04
ps ax | grep mysql
Then the answer was that it wasn't running, so I did
sudo service mysql start
Or try
sudo /etc/init.d/mysql start
Solution 2 - Mysql
Firstly, please confirm mysql-server is installed. I have the same error when mysql-server is installed but corrupted somehow. I do the trick by uninstall mysql completely and reinstall it.
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client
Solution 3 - Mysql
This took me ages to figure out but could you try the same -
1 - Update and Upgrade
sudo apt-get update
sudo apt-get upgrade
2 - Purge MySQL Server and Client (if installed).
sudo apt-get purge mysql-server mysql-client
3 - Install MySQL Server and Client fresh
sudo apt-get install mysql-server mysql-client
4 - Test MySQL
mysql -u root -p
> enter root password
*** should get socket not found in /var/run/mysqld/mysql.sock
4 - Configure mysqld.cnf with nano of vi
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change bind-address from 127.0.0.1 to localhost
bind-address = localhost
** Write and Exit
5 - Restart MySQL
sudo /etc/init.d/mysql restart
6 - check mysql
mysql -u root -p
> enter root password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
You should get in to mysql cli now.
Hope this helps
Code.Ph0y
Solution 4 - Mysql
I had the same problem when i installed xampp on my system. The mysql server looks for /var/run/mysqld/mysqld.sock but the mysql.sock file was in xampp folder so i used
find / -name '*.sock'
to find the mysql.sock file and then used
ln -s <the file location> /var/run/mysqld/mysqld.sock
to get a link for the *.sock file then tried mysql and it ran without error. Hope this could solve yours.
Remember to create the directory if it does not exists.
Solution 5 - Mysql
The client should be set consistent with server setting.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
Solution 6 - Mysql
You don't need to reinstall MySQL server I was facing the same issue but I have resolved the issue by running these commands.
ps -A|grep mysql
sudo pkill mysql
ps -A|grep mysqld
sudo pkill mysqld
sudo service mysql restart
mysql -u root -p
Solution 7 - Mysql
recently i have faced with this error in my mysql
ERROR 2002 (HY000)
:
> Can't connect to local MySQL server through socket > > '/var/lib/mysql/mysql.sock' (111)
because i forget to start my mariadb. just type this command on ur terminal.
systemctl start mariadb.service
Solution 8 - Mysql
In the linux terminal, I run the following steps and they helped me out
1.First of all list all the mysql packages installed
sudo dpkg -l | grep mysql
2.Delete the listed packages with the listed command
sudo apt-get --purge autoremove <package name>
3.Reinstall mysql server
sudo apt-get install mysql-server
This worked for me, Hope this works for you aswell.
Alternatively Try
sudo apt-get remove --purge mysql-\
then reinstall with
sudo apt-get install mysql-server mysql-client
Solution 9 - Mysql
I deleted everything connected to mysql with
> sudo apt-get remove --purge --auto-remove mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 > > sudo rm -r /etc/mysql* /var/lib/mysql* /var/log/mysql*
and then reinstalled it again with
> sudo apt-get update > > sudo apt-get install mysql-server
and then started it with
> mysql -u root -p
followed by the password
Solution 10 - Mysql
You may be missing mysql-server. install it using
sudo apt-get install mysql-server
Solution 11 - Mysql
This is an old tread with different solution proposed, but none of them worked for me. I'm adding this answer in the hope it will help somebody who struggled as me for some time.
I've checked all the existing answers and all the existing solution, but for me the issue was incorrect user permission on var/run/mysql
folder.
I've checked the user permission on that folder and it was set to root
. Once i changed to mysql:mysql
the problem has gone.
So enter into /var/run/mysqld
and change the user permission to:
chown -R mysql:mysql .
Solution 12 - Mysql
I had the problem.
This process worked for me:
> Ensure that during remove process you choose No to deleting database.
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client
Solution 13 - Mysql
I had the same problem after altering my.cnf. I resolved this problem next steps.
First : to find the location of error.log, look at 'my.conf'.
Second : I looked up error.log, I found next massages,
"unknown variable 'default-......' " ..... " mysqld_safe Starting mysqld darmon with from /var/lib/mysql "
Third : I reset my.conf to the default, then restart, this problem was resolved.
I hope this helps.
Solution 14 - Mysql
I have follow Wellington Lorindo posting. And My problem was solved.
Steps
- run in terminal
> ps ax | grep mysql
Result was
11200 ? Ssl 0:01 /usr/sbin/mysqld
11514 pts/0 S+ 0:00 grep mysql
Steps 2. Again type this
> sudo service mysql start
And problem solved.
Thanks Wellington Lorindo
Solution 15 - Mysql
The same error occured with my system as well. I had to remove mysql-server and reinstall it. Not other way around. Try running these commands it it works:
- sudo apt-get purge mysql-server
- sudo apt-get autoremove
- sudo apt-get install mysql-server
Solution 16 - Mysql
this worked for me
sudo /etc/init.d/mysql start
first i tried this, but i dont understand why it doesn't work this way
sudo service mysql start
Solution 17 - Mysql
On Debian this was a bind problem for me so changing bind-address
from localhost
to 0.0.0.0 helped.
vim /etc/mysql/my.cnf
bind-address = 0.0.0.0
Solution 18 - Mysql
I also met this problem.
mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Then I find the reason is my selinux
is enforcing, I disable it then restart mysqld
, it works, hope helpful.
Solution 19 - Mysql
There is another chance of you to get this particular error if you modify the max_connections
in my.cnf
file.
I also faced the same error which did not let me log in to MySQL server. In my case the problem was, I had to increase the max_connections
size in
> /etc/mysql/my.cnf
to
set-variable = max_connections = 5000
Due to this reason next day when I stared MySQL server it threw this error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Removing the set-variable = max_connections = 5000
segment from my.conf
file did the trick. After removing that particular segment following command was used. MySQL server started up and running like previously.
sudo /etc/init.d/mysql start
Solution 20 - Mysql
Try this:
sudo dpkg-reconfigure mysql-server-{version_number}
version_number
should be mysql version number. For example
sudo dpkg-reconfigure mysql-server-5.6
Then access mysql like this:
mysql -u root -p
Solution 21 - Mysql
If you are using wsl on windows 10 with ubuntu you can run:
-
sudo /etc/init.d/mysql start
the commandsudo service start mysql
wont work because you need to configure it. You can find how here
Solution 22 - Mysql
If you look close, you'll see the difference:
- The server listens on
/var/run/mysqld/mysqld.sock
- The client tries to connect to
/var/run/mysqld/mysql.sock
You'll have to adjust the one or the other.
Solution 23 - Mysql
Two main reasons:
-
mysql-server isn't installed! You have to install it (mysql-server and not mysql-client) and run it.
-
It's installed by default and running. So, it's not possible to run it again through Xampp or Lampp. You have to stop it: sudo service mysql stop
then you can start it through Xampp. It's possible to check if it's running or not with this code: sudo netstat -tap | grep mysql
If you see a result like this: tcp 0 0 localhost:mysql : LISTEN 1043/mysqld
It means that it's running properly.
Solution 24 - Mysql
make sure the bind address configuration option in the my.cnf file in /etc/ is the same with localhost or virtual serve ip address. plus check to make sure that the directory for creating the socket file is well specified.
Solution 25 - Mysql
This provides an alternative solution if the issue relates to you. If your disk drive is full than the MYSQL server (and most other programmes) is unable to start. Delete files and folders to allow Mysql-server to start up.
Solution 26 - Mysql
Simple: run these codes:::
1:: ls -lart/var/run/my*
2::mkdir /var/run/mysqld
3::touch /var/run/mysqld/mysqld.sock
4:ls -lart /var/run/mysqld
5::chown -R mysql /var/run/mysqld
6::ls -lart /var/run/mysqld
REstart your mysql server
then finaly type mysql -u root or mysql -u root -p and press enter key. thanks
Solution 27 - Mysql
In my case the problem was that I had added "default-character-set=utf8" to my.cnf and that was corrupting the file. Instead change that line for "character_set_server=utf8". That should solve it, hope this helps.
Solution 28 - Mysql
Note that I ran into this trouble after I upgraded my Ubuntu 14.04 distribution using apt-get upgrade
. I had to completely purge mysql-server
and mysql-client
and reinstall it to fix this issue.
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get purge mysql-server mysql-client
sudo apt-get install mysql-server mysql-client
Hope this helps.
Solution 29 - Mysql
This problem will occurred due to some unnecessary changes made in my.cnf file.
Try to diff /etc/mysql/my.cnf
with one of working mysql servers my.cnf file.
I just replaced /etc/mysql/my.cnf
file with new my.cnf file and this works for me.
Solution 30 - Mysql
I was stuck with this error too, and it took almost 3 hours to find it.
First of all, try to recall the changes that you made to your conf file, then undo the changes and save the file and start mysql. If you want to make any changes to the conf file, then stop mysql server and then change the desired values and restart mysql.
This error occurs because of an incorrect (wrong keyword or wrong value assigned) change made to the conf file. Most of the times this error occurs even if you restart the machine running the server, as the server is stopped, in that case, start mysql server.
Solution 31 - Mysql
I have the same problem and tried all the solutions posted here like :
sudo apt-get autoremove mysql-server
but unfortunately it doesn't work for me on ubuntu 16.04. To uninstall the right package you need to :
sudo apt-get remove mysql-
when you tried to autocomplete using tab
the command it will list the following package :
mysql-client mysql-client-core-5.7 mysql-server mysql-server-core-5.7 mysql-workbench mythes-en-us
mysql-client-5.7 mysql-common mysql-server-5.7 mysql-utilities mysql-workbench-data
obviously choose the mysql-server-core-5.7
so it would be :
sudo apt-get remove mysql-server-core-5.7
and now you can uninstall all mysql and reinstall again using these command from johnny's answer :
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client
Now I solved it and the Error is GONE.
Solution 32 - Mysql
Once you install or update MySQL, it won't ask you to create the root password. In that case: you will have file called "debian.cnf" path: /etc/mysql. You will find user name and password, login with that credentials and create new user and password.
Solution 33 - Mysql
I checked the mysql log in the cd /var/lib/mysql
directory in the mysql-error.log
file with the command tail -n 200 mysql-error.log
and identified ([ERROR]
) that there were two wrong variables in my.ini, after I removed them I was able to start the mysql service with the command /etc/init.d/mysql start
or service mysql start
Solution 34 - Mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
I get the error above when I try to log into MYSQL after installing it using brew, I am running MacOs, Oh yea I also noticed mysql is running I have restarted numerous times with no luck resolving the issue along with removing mysql and numerous reinstalls!
So simple I could slap myself, no but really, I solved this by CD into the temp folder that contains mysqlx.sock and mysql.sock.lock files, I deleted the single sock.lock file only and this solved my issue after doing so and I can log into mysql using the mysql -uroot command. Here are the commands I used. (this issue had me hung up for a while)
~ cd /tmp
/tmp ls
(this will list all the sock files in the temp folder, output shown below)
com.apple.launchd.8AgGW2s9Bb mysql.sock.lock
com.apple.launchd.batxrSISAJ mysqlx.sock
com.apple.launchd.cRCaxtT41m mysqlx.sock.lock
com.google.Keystone powerlog
then run
rm -R mysql.sock.lock
(use command above to remove the sock.lock file from the /tmp directory this resolved my issue)
hope this helped :)
Solution 35 - Mysql
You must do:
ls -lart /var/run/mysqld/
mkdir /var/run/mysqld
touch /var/run/mysqld/myssqld.sock
ls -lart /var/run/mysqld/
chown -R mysql /var/run/mysqld/
ls -lart /var/run/mysqld/
/etc/init.d/mysql restart
Then access like so:
mysql -u root -p
mysql> show databases;
Solution 36 - Mysql
rm -rf mysql.sock
service mysqld restart