0

I'm using mysql in docker. I can access docker through docker exec terminal. But I can't access it outside through my regular terminal or sequel ace.

What I'm getting in in sequel ace and in regular terminal

Access denied

Unable to connect to host 127.0.0.1 because access was denied.

Double-check your username and password and ensure that access from your current location is permitted.

MySQL said: Access denied for user 'crowdtank'@'localhost' (using password: YES) Access denied for user 'crowdtank'@'localhost' (using password: YES)

Terminal command and output for access attempt ERROR 1045 (28000): Access denied for user 'crowdtank'@'localhost' (using password: YES)

My docker code

version: '3'

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "8080:80"
    volumes:
      - ./src:/var/www
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
     - laravel

  mysql:
    image: mysql:5.7.22
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports: 
      - "3306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: crowdtank
      MYSQL_USER: crowdtank
      MYSQL_PASSWORD: crowdtank
      MYSQL_ROOT_PASSWORD: crowdtank
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./src:/var/www
    ports:
      - "9000:9000"
    networks:
      - laravel
zia sultan
  • 340
  • 3
  • 17
  • Did you edit the password at any point? Clean out `./mysql` folder and try again – OneCricketeer Aug 16 '21 at 09:38
  • Alternatively, add another container for phpmyadmin – OneCricketeer Aug 16 '21 at 09:39
  • 1
    please, share commands you use to connect to dockerized mysql – rok Aug 16 '21 at 09:41
  • THis is my command for try to access the sql crowdtank % mysql -u crowdtank -p And output is ERROR 1045 (28000): Access denied for user 'crowdtank'@'localhost' (using password: YES) – zia sultan Aug 16 '21 at 09:44
  • 1
    You most probably started your mysql container against a preexisting mysql data filesystem. If this is the case, restart on a fresh empty db data filesystem. More info here: https://stackoverflow.com/questions/59838692/mysql-root-password-is-set-but-getting-access-denied-for-user-rootlocalhost/59839180#59839180 – Zeitounator Aug 16 '21 at 09:45
  • I tried this command docker-compose down -v docker-compose up -d but not working – zia sultan Aug 16 '21 at 09:48
  • Does it work with `docker exec -it mysql mysql -u crowdtank -p crowdtank`? – digijay Aug 16 '21 at 13:03
  • yes its work. I think there's something I'm missing or some configuration needed. – zia sultan Aug 16 '21 at 13:06
  • I think Zeitounator is right and you have a mysqld running on the host. You could check it with `netstat -tulpen | grep 3306` and then try it again after stopping the service. – digijay Aug 16 '21 at 14:22
  • how to check this in mac? – zia sultan Aug 16 '21 at 14:49

0 Answers0