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
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.and in your django application add
'OPTIONS'
field.If in case you don’t want ssl enabled you can configure mariaDB to allow non-ssl connections. Just modify your
.cnf
file.and restart the mariaDB server by command
sudo systemctl restart mariadb
.Addtionally check the necessary python packages to support ssl for example –
mysqlclient
orPyMySQL
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.
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