Configuring Django and MySQL is not hard as it seems, just with the right commands its few steps works. Django is a web framework for python and MySQL is relational database management system. Together they are perfect for each other.

MySQL can easily handle around 1 million records. In one of my web application developed in Django, had 1.5 million records and it is working perfectly fine (I had to do partitioning in MySQL when the number of records increased to 1 million).

Lets see towards configuration, but there are few prerequisites:

  • Install Django
  • Install MySQL
  • Python connector for MySQL

Now I hope you already have Django and MySQL installed in your Mac OS X, so you only need to install python connector (you can skip this part if you already have MySQLdb working in your mac).

Install MySQL-python

While configuring Django and MySQL setup, sometimes people get errors in mac os x while installing “MySQL-python” using pip or easy_install, so there is a workaround, you should first install “Homebrew”(its a missing package manager for mac os x) and then run these commands

brew install mysql-connector-c
sudo pip install MySQL-python

Now lets move to configuration of Django and MySQL, its same across all versions of Mac OS X( 10.10 Yosemite, 10.9 Mavericks, 10.8 Mountain Lion etc)

Configure Django with MySQL

Step 1: Open MySQL command line by typing this command, you might prompted for password so you’ll have to enter the password of user “root” which you would have set during installation of MySQL.

mysql -u root -p

Step 2: Create a database for your django project and grant access to this database.

create database database_name;
GRANT ALL PRIVILEGES ON database_name.* TO 'any_username'@'localhost' IDENTIFIED BY 'password';

Step 3: Open settings.py of your django project and under database section add these lines

DATABASES = {
               'default': {
                    'ENGINE': 'django.db.backends.mysql', 
                    'NAME': 'database_name', 
                    'USER': 'any_username',
                    'PASSWORD': 'password',
                    'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
                    'PORT': '', # Set to empty string for default.
       }
}

Step 4: Open terminal and navigate to your project root directory and run this command

python manage.py syncdb

 

Also read:  How to use the spotlight search on iPhone?

Hope this helps. If you still have any issues of suggestions please post them in comments

Did you like it?
Please Rate it below:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...