Creating a database
Computer terminal
mysql -uroot -P Enter the password to log in to the mysql terminalcreateDatabase Renran (Project name)default charset=utf8md4; Create database renrancreate user renran identified by"122"; Example Create account renran with the password122
grand all priviliges on x.* to
grant all privileges on renran.* to "renran"@The '%'; The rights granted to renran's project are granted to Renran's account mysql (the former is the project, the latter the account)>flush privileges; # Flush down the toiletCopy the code
Mysql > delete user renrandatabase; create user renren
In this case, the renran account already exists. Run the following command to delete the account
drop user 'renran'@The '%';
Copy the code
Configuring database Connections
Open the Settings /dev.py file and configure it
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql"."HOST": "127.0.0.1"."PORT": 3306."USER": "renran_user"."PASSWORD": "renran"."NAME": "renran",}}Copy the code
Import Pymysql in __init__.py of the project main module
import pymysql
pymysql.install_as_MySQLdb()
Copy the code
Adjust the error
An error occurred running manage.py
This is because the default encoding of the database version causes the content returned by the Query to change a line of code incorrectly