在 ubuntu 14.04 中无法通过 socket '/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34265416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in ubuntu 14.04
提问by Suraj
I have installed LAMP on my Ubuntu machine.
我已经在我的 Ubuntu 机器上安装了 LAMP。
Where Apache2 and PHP5 have been installed properly as when I run apache2 -v
and php5 -v
I am getting their installed versions.
Apache2 和 PHP5 已正确安装,就像我运行时一样apache2 -v
,php5 -v
我正在安装它们的版本。
But I am not sure how do I check If My-SQL
is properly installed or not.
但我不确定如何检查My-SQL
是否正确安装。
Because when I run mysql -u root -p
command, I am getting the below error.
因为当我运行mysql -u root -p
命令时,我收到以下错误。
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ERROR 2002 (HY000): 无法通过 socket '/var/run/mysqld/mysqld.sock' 连接到本地 MySQL 服务器 (2)
Please help!
请帮忙!
回答by Khalil Meg
try to force redefining the root password:
尝试强制重新定义 root 密码:
sudo service mysql stop
sudo /usr/bin/mysqld_safe --skip-grant-tables &
mysql -h localhost
(now we are using mysql without carring to user privileges)
(现在我们使用 mysql 而不考虑用户权限)
> USE mysql
> UPDATE mysql.user
SET authentication_string=PASSWORD('new_password')
WHERE user='root' AND host='localhost';
> quit
sudo mysqladmin shutdown
sudo service mysql start
that's all ... now try to use mysql with the new password, like that:
这就是全部......现在尝试使用带有新密码的mysql,如下所示:
mysql -uroot -p
Enter password: enter the new_password
it should work :)
它应该工作:)
回答by cocoboy
you could try starting your mysql first
你可以先尝试启动你的mysql
> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
>
> service mysql start or service mysql start
回答by AJTech Solutions
For resolving this issue, you need to run following commands sequentially
要解决此问题,您需要按顺序运行以下命令
sudo service mysql stop
sudo /etc/init.d/apparmor reload
sudo service mysql start
After that you can run the following command to go to mysql console
之后,您可以运行以下命令转到 mysql 控制台
mysql -u root -p
mysql>
回答by Manish R
You need to first start mysqld service on your machine. Use below command to start mysqld service
您需要先在您的机器上启动 mysqld 服务。使用以下命令启动mysqld服务
service mysqld start
回答by nikhil
Had the same issue and done so much of troubleshooting
遇到了同样的问题并做了很多故障排除
finally i resolved the isssue by
最后我解决了这个问题
Creating a error.log file
创建一个 error.log 文件
steps
脚步
create a log file under /etc/var/log/error.log
在 /etc/var/log/error.log 下创建日志文件
start mysql using the command
使用命令启动mysql
systemctl start mysql.service
systemctl 启动 mysql.service
After this mysql started sucessfully
在这个mysql成功启动之后
回答by Gerard Pietrykiewicz
Not sure if that would be helpful but I run into the same issue on my VPS. As it turned out I have run out of space by doing an hourly backup.
不确定这是否有帮助,但我在 VPS 上遇到了同样的问题。事实证明,我每小时进行一次备份,空间不足。
try this:
尝试这个:
df -h
If you have 100% of disk usage then the server cannot write anything to the disk, no logs, no temp files, nothing.
如果您有 100% 的磁盘使用率,则服务器无法向磁盘写入任何内容,没有日志,没有临时文件,什么也没有。
I have removed some old backups. First find them (run inside backup folder)
我删除了一些旧的备份。首先找到它们(在备份文件夹中运行)
find . -type f -name "backup-2016-01*"
This command will find any file whit name starting with backup-2016-01...
此命令将查找名称以 backup-2016-01... 开头的任何文件。
Then delete those files:
然后删除这些文件:
find . -type f -name "backup-2016-01*" -delete
Or move them to a different location. Then fun the df -h again to see if you have more space. It helped me.
或者将它们移动到不同的位置。然后再次玩转 df -h 以查看是否有更多空间。它帮助了我。
回答by Ken Ratanachai S.
In my case, the cause of this error was my server ran out of memory. Check if that's the case by running
就我而言,此错误的原因是我的服务器内存不足。通过运行检查是否是这种情况
sudo journalctl -xe
# See if there's message below
Out of memory: Kill process 20967 (mysqld) score 155 o
If that's the case then it's time to Upgrade your server!
如果是这种情况,那么是时候升级您的服务器了!