taha maatof
taha maatof

Reputation: 2165

RSA Encryption not supported - caching_sha2_password with django mysql and docker

im trying to connect Mysql with django using docker, and i get this error

2061, 'RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support'.

i tried changing user and creating a database with

// create a user //

CREATE USER 'user'@'localhost' IDENTIFIED BY 'user';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
CREATE USER 'user'@'%' IDENTIFIED BY 'user';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;

// create a database //

CREATE DATABASE user_db;

BUT still the sqme error message

in the settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'user_db',
        'USER': 'user',
        'PASSWORD': 'user',
        'HOST': 'db',
        'PORT': '3306',
    }
}

and in docker-compose:

db:
    image: mysql:latest
    environment:
        MYSQL_DATABASE: 'user_db'
        MYSQL_USER: 'user'
        MYSQL_PASSWORD: user
        MYSQL_ROOT_PASSWORD: root
    volumes:
        - ./data/mysql/db:/var/lib/mysql
    ports: 
        - 3306:3306

thank you for your help.

Upvotes: 8

Views: 12570

Answers (5)

yaach
yaach

Reputation: 462

I had the same issue with docker-compose and two services (web and db). I was using Mysql 8.0 image and for django I was using python:3-10-buster.

I solved the issue by changing the web image to python:3-10-bullseye.

Upvotes: 0

Carlos Eduardo
Carlos Eduardo

Reputation: 1

use:

DATABASES = {
    'default': {
        #'ENGINE':   'django.db.backends.mysql',
        'ENGINE':   'mysql.connector.django',
        'NAME':     getenv('MYSQL_DATABASE'),
        'USER':     getenv('MYSQL_USER'),
        'PASSWORD': getenv('MYSQL_PASSWORD'),
        'HOST':     'db',
        'PORT':     getenv('MYSQL_PORT', 3306),
        'OPTIONS': {
            'auth_plugin': 'mysql_native_password'
        }
    }
}

or in your DSN, add:

mysql://USER:PASS@HOST(:PORT)/DATABASE?auth_plugin=mysql_native_password

Upvotes: 0

user1012513
user1012513

Reputation: 2355

I have added RUN apt-get update && apt-get upgrade -y in my docker file and it solved all issues.

You can simply run the command apt-get update && apt-get upgrade -y in the container before building.

Upvotes: 0

Alfredo Toselli
Alfredo Toselli

Reputation: 51

Seems a Debian version problem. Setting the "FROM" python image to 3.10.8-slim-bullseye permitted me to mantain: caching_sha2_password, MySql-8, mysqlclient native driver.

FROM python:3.10.8-slim-bullseye

Upvotes: 5

Sergio Valdez
Sergio Valdez

Reputation: 146

I have solved this changing the conector to mysql-connector-python==8.0.26 instead mysqlclient==2.0.3

Also, connection settings

DATABASES = {
    'default': {
        #'ENGINE':   'django.db.backends.mysql',
        'ENGINE':   'mysql.connector.django',
        'NAME':     getenv('MYSQL_DATABASE'),
        'USER':     getenv('MYSQL_USER'),
        'PASSWORD': getenv('MYSQL_PASSWORD'),
        'HOST':     'db',
        'PORT':     getenv('MYSQL_PORT', 3306),
        'OPTIONS': {
            'auth_plugin': 'mysql_native_password'
        }
    }
}

Upvotes: 9

Related Questions