django-admin startproject send_mail_prj
cd send_mail_prj
django-admin startapp app01
2.项目中 导入pymysql
send_mail_prj.__init__.py
import pymysql
pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()
3.项目配置文件配置MySQL
send_mail_prj.settings.py
DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘HOST‘: ‘192.168.60.72‘, #数据库的IP地址
‘PORT‘: ‘3306‘, #数据库连接时的TCP端口
‘USER‘: ‘root‘, #数据库登录用户名
‘PASSWORD‘: ‘123456‘, #数据库登录密码
‘NAME‘: ‘send_mail‘ #数据库名字
}
}
4.设置root账号可以远程登录
# 注意,在生产环境中,不要这么干
登录mysql后,执行如下SQL语句:
set global validate_password_policy=LOW;
set global validate_password_length=4;
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
flush privileges;