0

In trying to connect to connect to mysql using docker but I get the following logs below. How do I resolve this?

db_1           | Version: '5.7.34'  socket: '/var/run/mysqld/mysqld.sock'  port: 3307  MySQL Community Server (GPL)
db_1           | 2021-05-26T17:02:40.191347Z 2 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.259636Z 3 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.275977Z 4 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.361165Z 5 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.366075Z 6 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.367748Z 7 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.370714Z 8 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.372608Z 9 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:02:40.402829Z 10 [Note] Access denied for user 'admin'@'172.27.0.3' (using password: YES)
db_1           | 2021-05-26T17:05:14.885240Z 11 [Note] Access denied for user 'root'@'localhost' (using password: NO)

Docker Compose File

version: '3'
services:
  # redis:
  #   restart: always
  #   image: redis:latest
  #   expose:
  #     - "6379"

  db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_DATABASE: default_schema
      MYSQL_USER: admin
      MYSQL_PASSWORD: test
      MYSQL_ROOT_PASSWORD: *asus@2837
      MYSQL_TCP_PORT: 3307
    # volumes: 
    #   - .dbdata:/var/lib/mysql
    ports:
      - 3307:3307

  appseed-app:
    restart: always
    # env_file: .env
    command: gunicorn --bind 0.0.0.0:5006 core.wsgi:application
    build: ./app

    ports:
      - "5006:5006"
    # networks:
    #   - web_network

    # links:
    #   - redis
    depends_on:
      - db
      # - worker
    volumes:
      # - /path/source/on/host:/path/destination/on/container
      - ./static/:/app/static
      - ./db.sqlite3:/app/db.sqlite3"



  # phpmyadmin:
  #   image: phpmyadmin/phpmyadmin
  #   container_name: pma
  #   links:
  #     - db
  #   environment:
  #     PMA_HOST: db
  #     PMA_PORT: 3307
  #     PMA_ARBITRARY: 1
  #   restart: always
  #   ports:
  #     - 8083:86
  nginx:
    restart: always
    image: "nginx:latest"
    ports:
      - "86:86"
    volumes:
      - ./app/nginx:/etc/nginx/conf.d
      - ./app/static/:/static
    # networks:
    #   - web_network
    depends_on:
      - appseed-app

  # Celery worker
  # worker:
  #   build: ./app
  #   command: sh ./run_celery.sh
  #   links:
  #     - redis



  # flower:
  #   image: mher/flower
  #   environment:
  #     - CELERY_BROKER_URL=redis://redis:6379/0
  #     - FLOWER_PORT=8888
  #   ports:
  #     - 8888:8888
# networks:
#   web_network:
#     driver: bridge

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'default_schema',
        "USER": 'admin',
        "PASSWORD": "test",
        'HOST': 'db',
        'PORT': '3307',
    }
}
Philip Mutua
  • 6,016
  • 12
  • 41
  • 84
  • 1
    Not sure but this might answer your question: https://stackoverflow.com/questions/59838692/mysql-root-password-is-set-but-getting-access-denied-for-user-rootlocalhost – Abdul Aziz Barkat May 26 '21 at 17:32
  • 1
    If the credentials are correct, whether the mentioned host "172.27.0.3" exists in mysql.user table? my article explains other reasons https://www.rathishkumar.com/2017/04/error-1045-28000-access-denied-for-user-user-host-using-password-YES.html – Rathish Kumar B May 26 '21 at 18:19

1 Answers1

0

I had the same issue. My problem was that the volume from a previous docker compose up remained created. So every time I was launching my app, it was using the old volume to mount the mysql db and hence using old passwords.

I solved the problem by deleting the volume and relaunching the app.

  1. Stop your app: docker compose down
  2. List volumes: docker volume ls
  3. Find your app's volume and delete it: docker volume rm <volume_name>
chajo
  • 1
  • 2