Django无法连接到MySQL数据库

时间:2014-08-16 07:12:43

标签: django python-2.7 ubuntu-10.04

我是Django的新手。

我有一个简单的Django 1.3。*项目,我想在我的localhost上运行它。 我安装了所有必要的模块,如:python-mysqldb,rptz等... 我安装了python 2.7.2的ubuntu 10.04。 当我试图在终端启动项目时

thor@thor:/media/SAJAT - Projects/project/simple project$ python manage.py runserver

我收到以下错误消息:

> Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x1224910>>
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
    self.validate(display_num_errors=True)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.7/dist-packages/django/core/management/validation.py", line 102, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/usr/lib/python2.7/dist-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/usr/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
    self.cursor()
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 250, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 322, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '172.17.30.101' (110)")

我不知道这个IP地址来自172.17.30.101'(110),因为我的计算机上安装了mysql服务器(localhost)

这是我的settings.py文件

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'dbname',                      # Or path to database file if using sqlite3.
            'USER': 'dbuser',                      # Not used with sqlite3.
            'PASSWORD': '123456',                  # Not used with sqlite3.
            'HOST': '127.0.0.1',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
 #'PORT': '3306', i tried with this too                      # Set to empty string for default. Not used with sqlite3.
 #'PORT': '3360', i tried with this too                      # Set to empty string for default. Not used with sqlite3.
        },
        # 'read': {
        #     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        #     'NAME': 'newsonia',                      # Or path to database file if using sqlite3.
        #     'USER': 'dbuser',                      # Not used with sqlite3.
        #     'PASSWORD': 'dbname',                  # Not used with sqlite3.
        #     'HOST': '127.0.0.1',                      # Set to empty string for localhost. Not used with sqlite3.
        #     'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
        # }
    }

我不知道应该如何解决这类错误。

0 个答案:

没有答案
相关问题