skip to Main Content

I was working on a test project as a practice and when I tried migrating it to the database (MariaDB PhpMyAdmin), I get this error

django.db.utils.OperationalError: (2026, ‘TLS/SSL error: SSL is required, but the server does not support it’)

This is how I wrote it in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'schooldb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '3307',
        # 'OPTIONS': {'init_command': "SET SQL_MODE='STRICT_TRANS_TABLES'"},
    }
}

I already have mysqlclient installed.

3

Answers


  1. First what the error is telling that : your mariaDB server requires ssl connections, but the settings in your django application are not configured to use ssl.

    You need to reconfigure your mariaDB server to support ssl by modifying your .cnf or .ini file.

    [mysqld]
    ssl-ca = /path-to-ca-cert.pem
    ssl-cert = /path-to-server-cert.pem
    ssl-key = /path-to-server-key.pem
    

    and in your django application add 'OPTIONS' field.

    DATABASES = {
    ...
          'OPTIONS' : {
            'ssl': {
                'ca': '/path-to-ca-cert.pem',   
                'cert': '/path-to-server-cert.pem', 
                'key': '/path-to-server-key.pem',
            }
        }
    ...
    

    If in case you don’t want ssl enabled you can configure mariaDB to allow non-ssl connections. Just modify your .cnf file.

    [mysqld]
    require_secure_transport = OFF
    

    and restart the mariaDB server by command sudo systemctl restart mariadb .

    Addtionally check the necessary python packages to support ssl for example – mysqlclient or PyMySQL

    Login or Signup to reply.
  2. If you wish to connect without secure protocol,

    As documentation declares:

    ssl_mode
    If present, specify the security settings for the connection to the server. For more information on ssl_mode, see the MySQL documentation. Only one of ‘DISABLED’, ‘PREFERRED’, ‘REQUIRED’, ‘VERIFY_CA’, ‘VERIFY_IDENTITY’ can be specified.

    If not present, the session ssl_mode will be unchanged, but in version 5.7 and later, the default is PREFERRED.

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'schooldb',
            'USER': 'root',
            'PASSWORD': '',
            'HOST': '127.0.0.1',
            'PORT': '3307',
            'OPTIONS': {'ssl_mode': 'DISABLED'},
        }
    }
    
    Login or Signup to reply.
  3. I am also facing the same issue.
    Using the following libs and MySQL database:

    Django==5.1.2

    djangorestframework==3.15.2

    django-filter==24.3

    django-cors-headers==4.5.0

    markdown==3.7

    mysqlclient==2.2.5

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search