缺少mysql.sock;产生OperationalError:(2002,“Can not connect to local MySQL server through socket”/tmp/mysql.sock“(2)”) [英] Missing mysql.sock; yielding OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

查看:291
本文介绍了缺少mysql.sock;产生OperationalError:(2002,“Can not connect to local MySQL server through socket”/tmp/mysql.sock“(2)”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我发誓,我已经看过引用这个错误的每一个问题。几乎每个人都提供的解决方案是不同的,没有人似乎明白错误的系统原因。我和许多网络上遇到这个常见问题的人都需要,这是解释实际出错的原因。



基本上,当我尝试运行:

  python manage。 py shell 
from django.db import connection
cursor = connection.cursor()

与Django 1.4和python 2.7.3,我得到以下错误:OperationalError:(2002,无法通过套接字连接到本地MySQL服务器/tmp/mysql.sock(2))



我相信我的settings.py文件是正确的。并且我需要安装的一切安装。以下是settings.py:

  DATABASES = {
'default':{
'ENGINE' :'django.db.backends.mysql',#添加'postgresql_psycopg2','postgresql','mysql','sqlite3'或'oracle'。
'NAME':'database_name.mwb',#或使用sqlite3的数据库文件路径。
'USER':'user',#不与sqlite3一起使用。
'PASSWORD':'PASS',#不与sqlite3一起使用。
'HOST':'/tmp/mysql.sock',#设置为localhost的空字符串。不适用于sqlite3。
'PORT':'',#设置为空字符串为默认值。不适用于sqlite3。
}}

经过数周的时间冲刷网络以获得答案,包括每一个stackoverflow,我已经得出结论,我遇到的真正的问题是,我的电脑上没有mysql.sock文件,即使安装了mysql。那么真正的问题是如何得到一个?答案可能会令人尴尬。



当我运行时:

  cd / 
sudo find。 -name.sock

我什么也没有。是的,我已经在我的mac osx狮子上安装了mysql 5.25。这是绝对安装的:

  sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist 
com .mysql.mysqld:已经加载

但是,运行:

  mysql 

产生:

  -bash:mysql:命令未找到

很久以后,我发现这个错误: http:// bugs.mysql.com/bug.php?id=4174 ..所以有什么解决方案?



全面披露:我只是一个程序员。我真的不了解电脑。所以,我不知道任何关于mysql,数据库或套接字。我认为这个问题需要一个真正了解电脑的人来解决。因为虽然现在看起来很明显,但是将这个错误作为一个缺失的套接字花费了很长时间。 99%的网路上出现这个错误的人似乎没有以这种方式接近。

解决方案

你有mysql客户端安装但不是处理客户端连接的mysql-server。您需要安装mysql服务器并运行它。


Firstly, I swear that I have looked at every single question that references this error. Nearly every solution someone offers is different, and no one seems to understand the systemic reasons for the error. What I, and many people on the web who encounter this common problem, need, is an explanation of what is actually going wrong.

Basically, when I try to run:

python manage.py shell
from django.db import connection
cursor = connection.cursor()

with Django 1.4 and python 2.7.3, I get the following error: OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

I believe that my settings.py file is correct. And everything I need installed is installed. Here is the settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'database_name.mwb',                      # Or path to database file if using sqlite3.
    'USER': 'user',                      # Not used with sqlite3.
    'PASSWORD': 'PASS',                  # Not used with sqlite3.
    'HOST': '/tmp/mysql.sock',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
}}

After suffering through weeks of scouring the web for answers, including every one on stackoverflow, I have come to the conclusion that the real issue I am experiencing is that there no mysql.sock file on my computer, even though mysql is installed. So, the real question is how do I get one? The answer may be embarrassingly simple.

When I run:

cd /
sudo find . -name ".sock"

I don't get anything. And yes, I have installed mysql 5.25 on my mac osx lion. It's definitely installed:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
com.mysql.mysqld: Already loaded

However, running:

mysql

yields:

-bash: mysql: command not found

After a long time, I found this bug: http://bugs.mysql.com/bug.php?id=4174 .. so what's the solution??

Full disclosure: I'm just a programmer. I really don't know anything about computers. So, I don't know anything about mysql, databases, or sockets. I think this question will require somebody who really understands computers to fix. As, though it seems obvious now, it has taken a long time to formulate this error as being from a missing socket. 99% of people on the web with this error do not seem to be approaching it this way.

解决方案

You have the mysql client installed but not the mysql-server that handles connections for the client. You need to install the mysql server and run it.

这篇关于缺少mysql.sock;产生OperationalError:(2002,“Can not connect to local MySQL server through socket”/tmp/mysql.sock“(2)”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆