Reputation: 1
I downloaded The SQL API from here http://www.djangoproject.com/r/python-mysql/ (the official site) the problem is I don't know how to import it in django. for example whrn I type this:
from django.shortcuts import render_to_response
import MySQLdb
....
...
..
I get the following error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named MySQLdb
where should I extract the files, and what do I have to change to make it work ?
Upvotes: 0
Views: 3888
Reputation: 444
If you want to use mysql as database for django project you need:
pip install mysql-connector
)in settings.py setup default database for django project
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'name of your schema in mysql',
'USER': 'root',
'PASSWORD': '12345678',
'HOST': 'localhost',
'PORT': '3306',
}
}
Use commands like result = Something.objects.all() to query database (read django shell documentation for more info how to insert and take data from database Making queries)
If you just want to use mysql commands and data in django module, you use same system like in simple python:
pip install mysql-connector
)import mysql.connector
)conection= mysql.connector.connect(user='', host='', port='', password=''
)myquery=conection.cursor()
)myquery.execute("select yourdata from data.table")
)for q in myquery: results += q
)Example:
import mysql.connector
conection= mysql.connector.connect(user='root',
host='localhost', port='3306', password='12345678')
myquery=conection.cursor()
myquery.execute("select something from data.table")
for q in myquery:
results += q
Upvotes: 1
Reputation: 3865
When you extract it , cd into where you extracted it and run the setup.py file
python setup.py install
Upvotes: 3