[Solved-4 Solutions] ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Error Description:
- When we try to change password through terminal, we get:
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Solution 1:
- You can solve this problem 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.
- But if the mysql-server is already installed and is running, then you need to check the config files.
- The config files are:
- 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:
- Also (to see if it's running):
Solution 3:
To reset the password
Follow these steps:
- Stop mysql
Or for other distribution versions:
- Start MySQL in safe mode
- Log into MySQL using root
- Select the MySQL database to use
- Reset the password
- Flush the privileges
- Restart the server
- Stop and start the server again
Ubuntu and Debian:
On CentOS, Fedora, and RHEL:
- Login with a new password
- Type the new password and enjoy your server again like nothing happened
Solution 4:
- Log in as super user or use sudo
- 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 was localhost or 127.0.0.1
- Save and close the file.
- Come back to terminal and execute sudo service mysql start