Monday 12 November 2018

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)

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: Initializing buffer pool, size = 26.0G
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:38 InnoDB: Waiting for the background threads to start
131029 12:53:36 InnoDB: Completed initialization of buffer pool 131029 12:53:36 InnoDB: highest supported file format is Barracuda.
131029 12:53:39 [Note] - '0.0.0.0' resolves to '0.0.0.0';
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
Version: '5.5.34-0ubuntu0.12.04.1-log'
socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
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.
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: Initializing buffer pool, size = 26.0G
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:40 InnoDB: Waiting for the background threads to start
131029 13:17:38 InnoDB: Completed initialization of buffer pool
131029 13:17:38 InnoDB: highest supported file format is Barracuda.
131029 13:17:41 [Note] - '127.0.0.1' resolves to '127.0.0.1';
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
Version: '5.5.34-0ubuntu0.12.04.1-log'
socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu)
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.

 Answers


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



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.



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



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.



You may be missing mysql-server. install it using
sudo apt-get install mysql-server



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



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



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.



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
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



Two main reasons:
1) mysql-server isn't installed! You have to install it 
(mysql-server and not mysql-client) and run it.
2) 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.



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.



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.



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.



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.



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

0 comments:

Post a Comment