[英]Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in ubuntu 14.04
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 -v
和php5 -v
时,已经正确安装了Apache2和PHP5,我正在获取它们的安装版本。
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)
错误2002(HY000):无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器
Please help! 请帮忙!
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 :) 它应该工作:)
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
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>
You need to first start mysqld service on your machine. 您需要首先在计算机上启动mysqld服务。 Use below command to start mysqld service
使用以下命令启动mysqld服务
service mysqld start
Not sure if that would be helpful but I run into the same issue on my VPS. 不知道这是否会有所帮助,但是我在VPS上遇到了同样的问题。 As it turned out I have run out of space by doing an hourly backup.
事实证明,我每小时进行一次备份已用完了空间。
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.
然后再次使df -h好玩,看看是否有更多空间。 It helped me.
它帮助了我。
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! 如果是这样,那就该升级您的服务器了!
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成功启动之后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.