【发布时间】:2019-10-13 13:40:15
【问题描述】:
我已经在我的 windows 10 机器上安装了 mysql 5.1,我可以通过以下方式从 python 连接 mysql:
import pymysql
conn=pymysql.connect(host='localhost',user='root',password='MYSQLTB',db='shfuture')
然后我下载django框架并尝试使用它来连接mysql,我所做的是:
创建一个my.cnf文件内容是:
[client]
database = shfuture
host = localhost
user = root
password = MYSQLTB
default-character-set = utf8
将 settings.py 更改为:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': os.path.join(BASE_DIR, 'my.cnf'),
},
}
}
然后运行:
python manage.py runserver
但出现错误:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install the MySQL client?
我还需要在 Django 虚拟环境中安装额外的 MySQL 吗?如果我可以改用现有的 MySQL
【问题讨论】:
-
您需要安装客户端库才能访问 MySQL 服务器,而不是 MySQL 服务器本身。您的问题无法区分它们。