Access denied for Mysql in kubernetes pod with correct credentials

I’ve a problem accessing mysql in my kubernetes pod even if the credentials are correct ( my cluster is on minikube )

the error i’m getting:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

when i access my pod and type printenv i get this:

KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.96.0.1:443
HOSTNAME=keycloak-db-host-b98495f5b-bxn7h
MYSQL_MAJOR=8.0
HOME=/root
MYSQL_ROOT_PASSWORD=test
AUTH_SERVER_SERVICE_PORT_HTTP=8080
TERM=xterm
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
MYSQL_PASSWORD=test
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MYSQL_VERSION=8.0.21-1debian10
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
MYSQL_USER=djellalmohamedaniss

as you see, the env has the right values!

my secrets yaml file

apiVersion: v1
kind: Secret
metadata:
  name: keycloak-db-secrets
  namespace: hanouti-dz
stringData:
  username : djellalmohamedaniss
  password : test

when i fetch the secrets using kubectl i get:

enter image description here

i already used data and encoded my values with echo -n <value> | base64 but i had the same issue.

ps: to access my mysql pod, i’m using:

kubectl exec -ti -n hanouti-dz keycloak-db-host-b98495f5b-bxn7h -- sh

for the mysql image:

FROM mysql:8.0
RUN deluser mysql
RUN useradd mysql
RUN chown -R mysql:mysql /var/lib/mysql

mu kubernetes deployment :

...
- image: <image>
          name: keycloak-mysql-image
          env:
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  key: username
                  name: keycloak-db-secrets
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: keycloak-db-secrets
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  key: name
                  name: keycloak-db-conf
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: keycloak-db-root-secrets
...

Thanks in advance!

Source: Docker Questions