PyMySQL/mysqlclient

Authentication issue while connecting to database

namantam1 opened this issue · 2 comments

Describe the bug

When connecting to database deploy on a docker connector it throughs an error which says

MySQLdb.OperationalError: (2061, 'RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support')

To Reproduce

To reproduce create a minimal docker app with following config.

Code

Create a docker file

FROM python:3.8.10
RUN  apt-get update && apt-get install --no-install-recommends -y \
  gcc python3-dev default-libmysqlclient-dev build-essential gnutls-bin
RUN pip install mysqlclient
RUN apt install netcat -y

RUN echo "#!/bin/bash" > main.sh &&\
    echo "while ! nc -z db 3306; do sleep 3; done" >> main.sh &&\
    echo "python -c 'from MySQLdb import _mysql; print(_mysql.connect(host=\"db\",port=3306,user=\"test-user\",password=\"password\"))'" >> main.sh

CMD ["sh", "main.sh"]

Create a docker compose file

version: '3.9'

services:
  db:
    image: mysql
    restart: always
    volumes:
      - mysql_database:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: test-db
      MYSQL_USER: test-user
      MYSQL_PASSWORD: password

  app:
    build: .
    image: db-app
    depends_on:
      - db

volumes:
  mysql_database:

Environment

MySQL Client

  • OS - Windows 11, Ubuntu 20.04

  • Python3.8

Please let me know If I am doing anything wrong. I have tested this on both windows and an ubuntu machine.

If we keep running the database for long time and keep trying to connect sometime and sometimes not. Its very weird behavior.

Your are using Debian. default-mysql-client is mariadb client. It doesn't support new auth method.
You should use classic auth method, or install mysql client library that debian is not providing.

Thanks for your help 👍