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': '',
    }
}

1 Answer 1

2

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},
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

there is also 'OPTIONS': {'sslmode': 'require'} for postgres backend ref stackoverflow.com/q/47683059
It is trying to get ca attribute of ssl but it does not exist on bool value. So this one cause an error. see: github.com/django/django/blob/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.