V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
touch
V2EX  ›  Django

django 链接mysql时 提示2002错误

  •  
  •   touch · 2012-09-21 17:05:49 +08:00 · 3536 次点击
    这是一个创建于 4206 天前的主题,其中的信息可能已经有所发展或是发生改变。
    OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysql' (111)")

    我在django中设置是 'HOST': '/var/run/mysqld', 为什么还是会去/var/run/mysql 中找sock文件
    7 条回复    1970-01-01 08:00:00 +08:00
    cloudzhou
        1
    cloudzhou  
       2012-09-21 17:19:21 +08:00
    给出所有的settings信息,特别是数据库配置那一层
    touch
        2
    touch  
    OP
       2012-09-21 17:24:57 +08:00
    @cloudzhou

    4 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycop g2', 'mysql', 'sqlite3' or 'oracle'.
    15 'NAME': 'mysql', # Or path to database fi le if using sqlite3.
    16 'USER': 'root', # Not used with sqlite3.
    17 'PASSWORD': '123456', # Not used with sqlite3 .
    18 'HOST': '/var/run/mysqld', # Set to empty string for localhost. Not used with sqlite3.
    19 'PORT': '',
    napoleonu
        3
    napoleonu  
       2012-09-21 17:52:47 +08:00
    走TCP连接MySQL,即使是本地的MySQL。即:HOST用IP。
    touch
        4
    touch  
    OP
       2012-09-21 18:03:20 +08:00
    @napoleonu

    改ip还是2002错误
    4 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycop g2', 'mysql', 'sqlite3' or 'oracle'.
    15 'NAME': 'mysql', # Or path to database fi le if using sqlite3.
    16 'USER': 'root', # Not used with sqlite3.
    17 'PASSWORD': '123456', # Not used with sqlite3 .
    18 'HOST': '127.0.0.1', # Set to empty strin g for localhost. Not used with sqlite3.
    19 'PORT': '3306', # Set to empty string for default. Not used with s

    直接运用mysql又没问题
    touch
        5
    touch  
    OP
       2012-09-21 18:10:55 +08:00
    看了下my.cnf中的配置sock
    是 socket = /var/run/mysqld/mysqld.sock


    和报错的地址不一样
    cloudzhou
        6
    cloudzhou  
       2012-09-21 20:02:03 +08:00
    @touch 现在的2002错误是否和之前一样?如果配置了正确的sock地址之后呢?
    skydiver
        7
    skydiver  
       2012-09-21 20:04:00 +08:00
    注释里面写着呢, Set to empty string for localhost
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5390 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 07:56 · PVG 15:56 · LAX 00:56 · JFK 03:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.