phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
675 stars 455 forks source link

phpMyAdmin can't connect to mysql - both on same network. #360

Closed tcconway closed 1 year ago

tcconway commented 2 years ago

Somewhat new to Docker, so it might be a user error...

After having following several YT tutorials, I cannot get PHPMyAdmin to actually log in--I get the following errors:

My setup is: Docker with the default Laravel setup. Both 'mysql' and 'phpmyadmin' are in the 'sail' network.

Here's my docker-compose.yml:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s
    phpmyadmin:
        depends_on:
            - mysql
        image: phpmyadmin
        environment:
            - PMA_HOST = mysql
            - PMA_PORT = 3306
        networks:
            - sail
        ports:
            - 8080:80
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "redis-cli", "ping"]
            retries: 3
            timeout: 5s
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local
tcconway commented 2 years ago

Apparently setting - PMA_ARBITRARY=1 in the yml and then using 'mysql' during login works...

williamdes commented 2 years ago

Apparently setting - PMA_ARBITRARY=1 in the yml and then using 'mysql' during login works...

What about using

       environment:
            PMA_HOST: mysql
            PMA_PORT: 3306

it should work fine

tcconway commented 2 years ago

It's not working with PMA_HOST and PMA_PORT.

Having this...

        environment:
            - PMA_HOST = mysql
            - PMA_PORT = 3306

...doesn't work. I get the following errors when trying to log in: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known

When I use this...

        environment:
            - PMA_ARBITRARY=1

... I can type 'mysql' into the Server field and it allows me to log in.

Perhaps 'mysql' is not unique enough?

williamdes commented 2 years ago

Hi,

This is a bit strange, can you try the format I sent you to be sure this is not the cause of this issue ?

            PMA_HOST: mysql
            PMA_PORT: 3306

Perhaps 'mysql' is not unique enough?

It's just a name, phpMyAdmin will not complain about it ;)

gabrielmustiere commented 1 year ago

hey, same problems here, same network, and two syntax try

williamdes commented 1 year ago

hey, same problems here, same network, and two syntax try

What is your docker compose file?

gabrielmustiere commented 1 year ago

i have found the solution, juste remove PMA_PORT: 3306, only the host is enough

jaggersystems commented 1 year ago

The workaround for me was to use the local address of the docker host 10.10.10.x. Using the hostname would fail... I'll have to work out why the host couldn't resolve.

williamdes commented 1 year ago

I'll have to work out why the host couldn't resolve.

What is the host ?

Is it external on the computer name ?

jaggersystems commented 1 year ago

I'll have to work out why the host couldn't resolve.

What is the host ?

Is it external on the computer name ?

Local. I have the db and docker/phpmyadmin running on the same host.

pepps01 commented 4 months ago

You are only required to remove - PMA_PORT = 3306

cdubois54 commented 2 months ago

It's due to yaml syntax (with "-" and "=", do not add space after "=")

This is not working : - PMA_HOST= mysql

This is working : - PMA_HOST=mysql This is working : PMA_HOST: mysql

Now you can add PMA_USER and PMA_PASSWORD and you'll be automatically logged in PMA web interface