This guide will walk you through configuring MySQL as your database using a secure .cnf
file for sensitive credentials.
- Create a
.cnf
file that contains the necessary database connection information.
[client]
database = DB_NAME
host = localhost
user = DB_USER
password = DB_PASSWORD
default-character-set = utf8
⚠️ Note: Never hardcode personal or sensitive information in your project's codebase. Use the.cnf
file to protect your credentials.
In your Django project's settings.py
, update the DATABASES
configuration to use the .cnf
file for database credentials:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
}
}
- Replace
/path/to/my.cnf
with the actual file path to your.cnf
file.
- Fork this repository
- Create a new branch:
git checkout -b feature/<branch_name>
- Commit your changes:
git commit -m '<commit_message>'
- Push to the branch:
git push origin feature/<branch_name>
- Open a pull request