首先,您需要使用pip 为python 安装MySql,它可以在here 中找到。安装pip 后说pip install MySQL-python。希望它能让你开始使用 MySql。但是您可能还想使用可以找到here 的 Mysql python 连接器。请注意您使用的 Python 版本,然后下载连接器。您可能还想通过它安装可以找到 here,它将与所有先决条件,如 Python 连接器和服务器等。
在 settings.py 文件中
您需要更改数据库
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'password',
'HOST': '127.0.0.1', # Use this if Database exists in your PC or replace it by IP address of PC where you are fetching the Database
'PORT': '3306',
},
'mydb': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'password',
'HOST': '127.0.0.1', # Use this if Database exists in your PC or replace it by IP address of PC where you are fetching the Database
'PORT': '3306',
}
}
之后您应该能够访问 MySql 数据库。
同时在你的数据库文件中导入 MySql 为import MySQLdb