ERROR 2002 (HY000): Can't connect to local MyS

2018-12-31 07:16发布

I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin. I forgot the password and now I am unable to login. When I try to change password through terminal I get:

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

How can I fix this? I am unable to open LAMP, uninstall it or reinstall it.

30条回答
后来的你喜欢了谁
2楼-- · 2018-12-31 07:28

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

查看更多
路过你的时光
3楼-- · 2018-12-31 07:29

In my case it was that the disk was full and mysqld couldn't start anymore.

Try to restart mysql service.

service mysql restart

or

service mysql stop

service mysql start

If it doesn't recognize "stop" command then it's definitely the disk space. You should make some space in the partition mysql is allocated or make the disk larger.

Check the disk space with

df -h

查看更多
浮光初槿花落
4楼-- · 2018-12-31 07:30

I just experienced the same issue after I had to restart my production server. I am running Debian 8.1 (Jessie) on a DigitalOcean droplet.

This is what I did to resolve my issue:

  1. Check if the file /var/run/mysqld/mysqld.sock exists. If it doesn't, manually create it by entering touch /var/run/mysqld/mysqld.sock (which is what I had to do).

  2. So the MySQL process can use this file. Change ownership of said file by entering chown mysql /var/run/mysqld/mysqld.sock.

  3. Once '2' has been done, restart the MySQL service by entering service mysql restart or /etc/init.d/mysql restart.

After going through the above steps, my issue was solved. I rarely have this issue, and there is probably a better way, so by all means provide constructive feedback if need be :).

查看更多
残风、尘缘若梦
5楼-- · 2018-12-31 07:30

Your mysql-server might not be running. Ensure it runs by typing mysql.server start into the terminal.

查看更多
像晚风撩人
6楼-- · 2018-12-31 07:30

Here's what worked for me:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
service mysql restart

This creates a link.

查看更多
听够珍惜
7楼-- · 2018-12-31 07:31

If you're using Amazon EC2, and you're having this problem on the instance, then you only need to do:

sudo yum install mysql-server
sudo service mysqld restart

Amazon EC2 doesn't have a server installed (only the client is installed), so in case of that you need to install that on your instance, and after that try

 mysql -u root -p

to check if that worked.

查看更多
登录 后发表回答