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

Issue

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\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)")

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

UPD: I use MySQL-python-1.2.4.win-amd64-py2.7 with Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]

Solution

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

I tried this precompiled driver: http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python and it fails.

After it I tried this one: http://www.codegood.com/archives/129 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