5

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.

taha maatof
  • 1,862
  • 2
  • 9
  • 23
  • Please see following links to solve your issue https://stackoverflow.com/questions/50088142/authentication-method-caching-sha2-password-not-supported-by-any-of-the-availa https://stackoverflow.com/questions/49931541/mysql-changing-authentication-type-from-standard-to-caching-sha2-password?noredirect=1&lq=1 – SmartCoder Aug 08 '21 at 13:13
  • already tried that, i work with mysql from docker i don't have it on my system(i use Ubuntu), and the alter user and the create user solution are what i tried ,did't work, but thank you for your answer – taha maatof Aug 08 '21 at 13:17
  • have you tried to set everything to native password – nbk Aug 08 '21 at 14:03
  • i actually found out that this is a problem in MySQL version 8 , i changed it to an anterior version and everything works, with root or a user created, thank you for your help. – taha maatof Aug 09 '21 at 19:48

3 Answers3

8

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'
        }
    }
}
  • Removing `mysqlclient` and adding `mysql-connector-python==8.0.26` worked for me even without the `'OPTIONS': {...}` – Sojoodi Dec 07 '22 at 15:54
2

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
0

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.

user1012513
  • 2,089
  • 17
  • 14