2 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
1、指定連接pymysql(python3.x)
先配置_init_.py
import pymysql
pymysql.install_as_MySQLdb()
2、配置連接mysql文件信息
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_orm', #你的數(shù)據(jù)庫(kù)名稱
'USER': 'root', #你的數(shù)據(jù)庫(kù)用戶名
'PASSWORD': '', #你的數(shù)據(jù)庫(kù)密碼
'HOST': '', #你的數(shù)據(jù)庫(kù)主機(jī),留空默認(rèn)為localhost
'PORT': '3306', #你的數(shù)據(jù)庫(kù)端口
}
}
3、在mysql數(shù)據(jù)庫(kù)中,創(chuàng)建數(shù)據(jù)庫(kù)。
mysql> create database Django_ORM character set utf8;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| crm |
| django_orm |
| mysql |
| performance_schema |
| s1 |
| sys |
| t2 |
+--------------------+
- 2 回答
- 0 關(guān)注
- 908 瀏覽
添加回答
舉報(bào)