1

When I connect to my database with mysql I specify the option --ssl, or else I get the error

SSL connection is required. Please specify SSL options and retry.

I know that with MySQL you can connect with a ssl certificate where you have a copy of the certificate locally. With this approach I know how to move forward with Django, as you can specify the option as described here https://stackoverflow.com/a/12285601/2889451

However, in my case I simply pass the option --ssl, and I don't have a local copy of the certificate. How can I enable this option in Django?

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASSWORD,
        'HOST': DB_HOST,
        'PORT': '',
    }
}
Simen Russnes
  • 2,002
  • 2
  • 26
  • 56

1 Answers1

3

Apparently you can solve it by passing the options as shown below:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASSWORD,
        'HOST': DB_HOST,
        'PORT': '',
        'OPTIONS': {'ssl': True},
    }
}
Simen Russnes
  • 2,002
  • 2
  • 26
  • 56
  • there is also `'OPTIONS': {'sslmode': 'require'}` for postgres backend ref https://stackoverflow.com/q/47683059 – ddelange Jan 17 '23 at 15:47