[Solved]-Django, phpmyadmin and mysql?

12👍

You can definitely manage Mysql through the XAMPP interface. Try setting the DB_HOST in settings.py to “localhost”. If it doesn’t work, try “127.0.0.1”. This is typically caused by the python-mysql module expecting the mysql unix socket to be in another place than it is. Actually, I’m unsure if the mysql server uses a unix socket on Windows. Anyway, one of both should work 🙂
You can use the credentials you use to login with phpmyAdmin also for Django. Many consider it bad style to use root for non-administration tasks (and I agree), but for starters and on your development machine it isn’t too big of an issue.
phpMyAdmin should work out of the box with your django-managed databases.

My database settings.py block for mysql looks something like this:

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': 'USER',                      # Not used with sqlite3.
        'PASSWORD': 'PASSWORD',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

This is for django 1.2 and above. Replace DBNAME, USER and PASSWORD with the respective values and try ‘127.0.0.1’ as HOST if you run into problems. Obviously, you’d need to run ‘manage.py syncdb’ as you did with sqlite before you can use it.

4👍

I’d highly recommend checking out postgresql! It comes with a Sqlserver-Management-System-like Database Browser that runs on your desktop, rather than a web based front end. Now you don’t need to worry about configuring PHP alongside Django. Postgresql will probably be harder to install than MySql on XAMPP, but I believe that you can get a lot out of doing so.

Postgresql is also a lot better (IMO) than MySQL, and is the recommended database to use with Django according to a lot of the people close to Django.

That said, I currently use Oracle, so you probably shouldn’t listen to me. 🙂

3👍

You can easily manage your databases with phpMyAdmin. All what Django needs is permission and access information for your database. Once those are set up (granting permissions in phpMyAdmin and adding the access information in Django’s settings.py), you would issue a manage.py syncdb for example and you’re done.

Leave a comment