My Sql
Monday, January 25, 2021 9:13 AM
Connecting MySql with django:
----------------------------
1. Download MySql installer by using below url
https://dev.mysql.com/downloads/installer/
2. once u click on above url it will ask u to create a oracle account create
it by giving some random details
3. after that log in into that and download with default settings
4. while installing it will install the following packages
1. MySQL workbench
2. MySQL commandline client
3. MYSQL installer
4. MySql notifier
5. mysql-installer-web-community
5. After successfull installations search for mysql and click on
mysql commandline client
6. it will ask u to enter password
root (is the password)
7. syntax for creating database
create database databasename;
8. in order to use that created database by using below command
use databasename;
9.syntax to see the tables of Database
show tables;
10. syntax to retrieve the data
select * from Relationname;
Now we have to install Two python packages inorder to connect mysql to ur django
project
1. pip install pymysql
2. pip install mysql-connector-python
Now Configuring with in the settings.py tfile of ur project
-----------------------------------------------------------
import pymysql
pymysql.version_info=(1,4,6,"final",0)
pymysql.install_as_MySQLdb()
#now after this scroll down to database section
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'name of the database u have created',
'USER':'root',
'PASSWORD':'root',
'HOST':'localhost',
'PORT':3306,
}
}