无法使用Python 2.7从django网站连接到MySQL,但是使用Python 2.5是可以的

时间:2013-10-18 21:38:03

标签: python mysql django mysql-python

当我使用Python 2.7连接MySQL时,我得到:

    Traceback (most recent call last):
  File "C:\Programs\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 48, in inner_run
    self.validate(display_num_errors=True)
  File "C:\Programs\Python27\lib\site-packages\django\core\management\base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "C:\Programs\Python27\lib\site-packages\django\core\management\validation.py", line 102, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 313, in get_server_version
    self.cursor()
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\__init__.py", line 75, in cursor
    cursor = self._cursor()
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 297, in _cursor
    self.connection = Database.connect(**kwargs)
  File "C:\Programs\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Programs\Python27\lib\site-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 'localhost' (10061)")

当我使用带有MySQLdb驱动程序的Pyhton 2.5时,相同的代码/ mysql实例工作正常。 我该如何解决? 谢谢!

UPD :我使用MySQL-python-1.2.4.win-amd64-py2.7和Python 2.7.3(默认,2012年4月10日,23:24:47)[MSC v .1500 64位(AMD64)]

1 个答案:

答案 0 :(得分:0)

这个问题很奇怪,但看起来已经解决了。

我尝试了这个预编译的驱动程序:http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python但它失败了。

之后我尝试了这个:http://www.codegood.com/archives/129,没关系。