[英]how to get django to read MySQL password from my.cnf?
I have a .my.cnf file in my home directory so that, almost all the time, I can access my MySQL databases with just my username.我的主目录中有一个 .my.cnf 文件,因此几乎所有时间,我都可以仅使用我的用户名访问我的 MySQL 数据库。
However, in django, if I remove the password from the configuration in the settings.py, as seen below, the django app cannot access the database.但是,在 django 中,如果我从 settings.py 中的配置中删除密码,如下所示,django 应用程序无法访问数据库。
DATABASES = {
'default': {
'NAME': 'calaccess_raw',
'PASSWORD': 'ZuperZekretPazzword',
'ENGINE': 'django.db.backends.mysql',
'USER': 'ray',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'local_infile': 1,
}
}
}
It seems insecure that I need to put my password inside the settings.py file.我需要将密码放在 settings.py 文件中似乎不安全。 These tend to be included in git repositories and such and it seems a bad idea.
这些往往包含在 git 存储库等中,这似乎是一个坏主意。
So, is there a way to get the python MySQL driver being used by django to use the standard my.cnf files?那么,有没有办法让 django 使用的 python MySQL 驱动程序使用标准的 my.cnf 文件?
Under 'OPTIONS' you can specify a 'read_default_file' like this:在“选项”下,您可以指定一个“read_default_file”,如下所示:
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
Give that a try;试试看; hope it helps.
希望能帮助到你。
Docs: https://docs.djangoproject.com/en/1.7/ref/databases/#connecting-to-the-database文档: https : //docs.djangoproject.com/en/1.7/ref/databases/#connecting-to-the-database
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.