Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jakubjv's avatar

How connect to MySQL database container with table plus?

Hi everyone,

I’m trying to connect to a MySQL database through TablePlus. The database is running inside a container, and this is my first time containerizing a Laravel application. The build process goes smoothly and all services are running as they should, including the MySQL container.

The issue is that I’m not sure what the problem is with the connection in TablePlus. When connecting to the database via TablePlus, I use the password and username from the .env file. I have localhost as the host and 3306 as the port, and I’m entering the database name correctly, username is admin and password is password. However, I receive the error message "Access denied for user 'admin'@'localhost' (using password: YES)." This is a confusing error for me, and I’m not sure if I made a mistake somewhere.

This is my .env

DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME=admin
DB_PASSWORD=password
DB_ROOT_PASSWORD=root

this is my docker-compose

version: '3.8'

services:
  laravel:
    restart: unless-stopped
    container_name: laravelapp
    build:
      context: ../
      dockerfile: ./deploy/Dockerfile
    # allocate as many volumes as necessary, if needed.
    volumes:
      - ../:/var/www/html
      - ../storage/app:/var/www/html/storage/app
    environment:
      APP_NAME: ${APP_NAME}
      APP_ENV: ${APP_ENV}
      APP_DEBUG: ${APP_DEBUG}
      APP_KEY: ${APP_KEY}
      APP_VERSION: ${APP_VERSION}
      APP_URL: ${APP_URL}
      DB_CONNECTION: mysql
      DB_HOST: database
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      MAIL_MAILER: ${MAIL_MAILER}
      MAIL_HOST: ${MAIL_HOST}
      MAIL_PORT: ${MAIL_PORT}
      MAIL_USERNAME: ${MAIL_USERNAME}
      MAIL_PASSWORD: ${MAIL_PASSWORD}
      MAIL_ENCRYPTION: ${MAIL_ENCRYPTION}
      MAIL_FROM_ADDRESS: ${MAIL_FROM_ADDRESS}
      MAIL_FROM_NAME: ${MAIL_FROM_NAME}
    ports:
      - "8080:80"
    networks:
      - n-laravel
    depends_on:
      - database

  database:
    restart: unless-stopped
    image: mysql:latest
    volumes:
      - v-database:/var/lib/mysql
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    networks:
      - n-laravel

  redis-cache:
    image: redis:latest
    container_name: redis
    restart: unless-stopped
    networks:
            - n-laravel
    ports:
      - "6379:6379"
    volumes:
      - ./:/var/www

volumes:
  v-database:


networks:
  n-laravel:
    driver: bridge

docker ps command output

1e057ffc9c70   mysql:latest     "docker-entrypoint.s…"   2 hours ago   Up 2 hours   3306/tcp, 33060/tcp              deploy-database-1
0 likes
1 reply

Please or to participate in this conversation.