1.首先自己创建数据库
create database luffy default charset=utf8mb4;
2.为当前项目创建数据库用户
create user luffy_user identified by 'luffy'; grant all privileges on luffy.* to 'luffy_user'@'%'; flush privileges;
3.在settings.dev文件中添加配置
DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "HOST": "127.0.0.1", "PORT": 3306, "USER": "luffy_user", "PASSWORD": "luffy", "NAME": "luffy", } }
4.
import pymysql pymysql.install_as_MySQLdb()
###也就是需要先安装pymysql模块