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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

Mysql on 老刘博客

暂无文章

Django设置使用MySql的时候遇到的一些坑
老刘 · 2022-11-18 · via Mysql 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