Can't connect to MySQL from django website with Python 2.7, but is ok with Python 2.5


When I use Python 2.7 to connect to MySQL I get:

    Traceback (most recent call last):
  File "C:\Programs\Python27\lib\site-packages\django\core\management\commands\", line 48, in inner_run
  File "C:\Programs\Python27\lib\site-packages\django\core\management\", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "C:\Programs\Python27\lib\site-packages\django\core\management\", line 102, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\", line 313, in get_server_version
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\", line 75, in cursor
    cursor = self._cursor()
  File "C:\Programs\Python27\lib\site-packages\django\db\backends\mysql\", line 297, in _cursor
    self.connection = Database.connect(**kwargs)
  File "C:\Programs\Python27\lib\site-packages\MySQLdb\", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Programs\Python27\lib\site-packages\MySQLdb\", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

The same code/mysql instance works fine when I use Python 2.5 with MySQLdb driver.
How can I fix it?

UPD: I use with Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]


This problem is strange, but looks like it is solved.

I tried this precompiled driver: and it fails.

After it I tried this one: and it is ok.

Answered By – dbf

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published