惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

Django on 老刘博客

Django部署在debian11服务器
Django设置使用MySql的时候遇到的一些坑
老刘 · 2022-11-18 · via Django on 老刘博客

Django默认使用的数据库是sqllit,如果是一个小项目的话是完全够用的,但是如果考虑到这个项目未来的话,一般都会换成Mysql或者其他更专业的数据库。本文,就来说说,在设置使用mysql的时候,遇到的一些问题及解决的方法。

OIP-C

项目里设置引用Mysql

在setting.py里,把原来使用sqllit的语句删除或者注释掉,添加如下代码

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',   # 数据库引擎
        'NAME': '',  # 数据库名,先前创建的
        'USER': '',     # 用户名,可以自己创建用户
        'PASSWORD': '',  # 密码
        'HOST': '127.0.0.1',  # mysql服务所在的主机ip
        'PORT': '3306',         # mysql服务端口
    }
}

安装Python访问MySQL的模块

Django官方已经不建议使用pymysql库了,而是改用mysqlclient,直接pip安装即可。

pip install mysqlclient

在debian11上安装的时候,显示OSError: mysql_config not found的错误,查询得知,需要安装libmysqlclient-dev,但是用apt install libmysqlclient-dev的时候,安装不成功,提示是另一个分支,建议安装libmariadb-dev。所以安装这个即可。

apt install libmariadb-dev

出错:error: command ‘x86_64-linux-gnu-gcc’ failed: No such file or directory

sudo apt-get install build-essential python3-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev