无法通过Remote上的套接字连接到本地MySQL服务器

时间:2017-07-13 15:39:25

标签: mysql django python-2.7 amazon-ec2

我正在使用Django远程Mysql数据库。使用django ORM插入db时,我收到类似

的错误

错误:

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

在搜索此错误时,我发现解决方案是确保数据库是否正常工作。但在我的情况下,它的远程mysql数据库。

mongodb的设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': MYSQL_DB,
        'USER': MYSQL_USER,
        'PASSWORD': MYSQL_PASSWORD,
        'HOST': MYSQL_HOST,  # Or an IP Address that your DB is hosted on
        'PORT': MYSQL_PORT
    }
}

错误的更多细节:

    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 367, in mysql_version
    with self.temporary_connection() as cursor:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection
    cursor = self.cursor()
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 263, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

任何人都可以在这里提出错误的建议。

0 个答案:

没有答案