Can't communicate with MySQL from django, but can directly in python
Question: I'm setting up a django web site locally on Windows with Apache, django 1.6
and MySQL 5.5.8. I've created a test database and populated it with a couple
of sample records in the MyPHPAdmin interface. It has a user specifically for
django, with full permissions (for that database only).

In a python session I can interact with the database using this function

    
    
    def TestConnection():
        import MySQLdb
        db=MySQLdb.connect(host="localhost", user="django", passwd="nu_django", db="nutana_django")
        cursor=db.cursor()
        cursor.execute("select * from test")
    
        for x in range(0,cursor.rowcount):
            row=cursor.fetchone()
            print row[0], ' --> ', row[1]
    

and it outputs the records of the db, so I seem to have MySQL, MySQLdb and
python working together properly.

Next, in django, I've created an app called Courses using "python manage.py
startapp Courses", and edited my settings.py file to include Courses in the
Installed_Apps and defined the database connection like this:

    
    
    ROOT_URLCONF = 'Nutana.urls'
    
    WSGI_APPLICATION = 'Nutana.wsgi.application'
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'nutana_django',
            'USER':'django',
            'PASSWORD': 'nu_django',
            'HOST':'127.0.0.1',
            'PORT':   '80'
        }
    }
    

Last step is Apache. I've added the WSGI module to apache and appended the
following to the end of the file:

    
    
    LoadModule wsgi_module modules/mod_wsgi.so
    
    WSGIScriptAlias /Nutana F:/Web_Django/Nutana/Nutana/wsgi.py
    WSGIPythonPath F:/Web_Django/Nutana
    <Directory F:/Web_Django/Nutana/Nutana/>
    <Files wsgi.py>
    Order deny,allow
    Allow from all
    </Files>
    </Directory>
    

where the paths above are all correct, but I'm not convinced are all
necessary.

Within f:\web_django\Nutana\Courses I've edited models.py to the following:

    
    
    from django.db import models
    
    # Create your models here.
    class Course(models.Model):
        Name = models.CharField(max_length=200)
        start_date = models.DateTimeField('Start Date')
        Quota = models.IntegerField()
    
    class Course_Venue(models.Model):
        Course = models.ForeignKey(Course)
        Name = models.CharField(max_length=200)
        Max_Size = models.IntegerField()
    

Ok... now when I run "python manage.py sql Courses" from the command prompt in
"f:\web_django\Nutana", where manage.py lives, I get an error:

    
    
    django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0")
    

That's a lot of configuration, and I don't know where I've gone wrong! I don't
think Apache is the issue here, but I've included it to be thorough. If I call
up a non existent web page the 404 error includes reference to wsgi, so maybe
thats all good?

    
    
    localhost
    16/12/2013 10:14:34 AM
    Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o mod_wsgi/3.3 Python/2.7.6 PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
    


Answer: MySQL server has port 3306 insted 80!

