ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Solution 1:
I once had this problem and solved it by installing mysql-server
, so make sure that you have installed the mysql-server
, not the mysql-client
or something else.
That error means the file /var/run/mysqld/mysqld.sock
doesn't exists, if you didn't install mysql-server
, then the file would not exist. So in that case, install it with
sudo apt-get install mysql-server
But if the mysql-server
is already installed and is running, then you need to check the config files.
The config files are:
/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf
In /etc/my.cnf
, the socket file config may be /tmp/mysql.sock
and in /etc/mysql/my.cnf
the socket file config may be /var/run/mysqld/mysqld.sock
. So, remove or rename /etc/mysql/my.cnf
, let mysql use /etc/my.cnf
, then the problem may solved.
Solution 2:
Try this:
mysql -h 127.0.0.1 -P 3306 -u root -p <database>
Also (to see if it's running):
telnet 127.0.0.1 3306
Probably it is just a misconfiguration in the my.cnf
file, in /etc/somewhere
(depending on the Linux distribution).
Solution 3:
I am seeing all these answers, but none offer the option to reset the password and no accepted answer. The actual question being he forgot his password, so he needs to reset, not see if it's running or not (installed or not) as most of these answers imply.
To reset the password
Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):
-
Stop
mysql
sudo /etc/init.d/mysql stop
Or for other distribution versions:
sudo /etc/init.d/mysqld stop
-
Start MySQL in safe mode
sudo mysqld_safe --skip-grant-tables &
-
Log into MySQL using root
mysql -u root
-
Select the MySQL database to use
use mysql;
-
Reset the password
-- MySQL version < 5.7 update user set password=PASSWORD("mynewpassword") where User='root'; -- MySQL 5.7, mysql.user table "password" field -> "authentication_string" update user set authentication_string=password('mynewpassword') where user='root';
-
Flush the privileges
flush privileges;
-
Restart the server
quit
-
Stop and start the server again
Ubuntu and Debian:
sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start
On CentOS, Fedora, and RHEL:
sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysqld start
-
Login with a new password
mysql -u root -p
-
Type the new password and enjoy your server again like nothing happened
This was taken from Reset a MySQL root password.
Solution 4:
I tried the following steps:
- Log in as
super user
or usesudo
- Open
/etc/mysql/my.cnf
using gedit - Find
bind-address
, and change its value to the database server host machine's IP address. For me, it waslocalhost
or127.0.0.1
- Save and close the file.
- Come back to terminal and execute
sudo service mysql start
And it worked for me.