skip to Main Content

Each time when I try to access the phpmyadmin from browser I receive this error:
“Cannot log in to the MySQL server”

I tried to change networks, restart docker.

version: '3'

services:
 web: 
  image: nginx:alpine
  ports:
   - 80:80
  volumes:
   - ./public_html:/public_html
   - ./conf.d:/etc/nginx/conf.d
  networks:
   - nginxphp

 php:
  image: php:7.1.11-fpm-alpine
  volumes:
   - ./public_html:/public_html
  expose:
   - 9000
  networks:
   - nginxphp

 db:
  image: mysql
  environment:
   MYSQL_ROOT_PASSWORD: root
  ports:
   - "3306:3306"
 phpmyadmin:
  image: phpmyadmin/phpmyadmin
  environment:
    MYSQL_ROOT_PASSWORD: root 
    MYSQL_USER: root
    MYSQL_PASSWORD: root
  depends_on:
   - db
  ports:
   - "8080:80"

networks:
    nginxphp:

Cannot log in to the MySQL server
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password] mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client

3

Answers


  1. Chosen as BEST ANSWER

    If you are using phpmyadmin with latest mysql version you will have some login issues:

    Cannot log in to the MySQL server mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password] mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client

    The solution is to downgrade to mysql 5.7 or another. I tested with mysql 5.7 and it works for me. If you want to can test with another versions and let the community know.

    Below is the docker-compose file that builds and run Nginx + php 7.1 + mysql 5.7 +phpmyadmin

    version: '3'
    
    services:
    
     web: 
      image: nginx:alpine
      ports:
       - 80:80
      volumes:
       - ./public_html:/public_html
       - ./conf.d:/etc/nginx/conf.d
      networks:
       - nginxphp
    
     php:
      image: php:7.1.11-fpm-alpine
      volumes:
       - ./public_html:/public_html
      expose:
       - 9000
      networks:
       - nginxphp
    
     db:
      image: mysql:5.7
      ports:
       - "3306:3306"
      environment:
       MYSQL_ROOT_PASSWORD: root
    
     phpmyadmin:
      image: phpmyadmin/phpmyadmin
      links:
       - db
      environment:
        PMA_HOST: db
        PMA_PORT: 3306
        MYSQL_USER: root
        MYSQL_PASSWORD: root
        MYSQL_ROOT_PASSWORD: root 
      depends_on:
       - db
      ports:
       - "8080:80"
    
    networks:
        nginxphp:
    

    Hope this will save some time to someone!


  2. Disclaimer: I’m not a Docker user!

    Your didn’t mention if you’re using the browser on the same computer as the sever or remotely. You’ll need access to the mysql server (mysqld) through a terminal (command prompt). If this is a new install, it must be on the computer that is running mysql server.

    In the Docker mysql page:
    “The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may include additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d.”

    Try looking in the /etc/mysql/my.cnf file on the server you’re trying access. first. You’re looking for:

    bind-address = x.x.x.x
    

    This is the address that the mysql server will talk to (“bound to”). Its typically “localhost” or “127.0.0.1”.

    To eliminate the error message like you see, I had to do two things:

    1) change ‘bind-address to 0.0.0.0’
    this allows the server to connect to any computer. However, THIS IS A SECURITY RISK. Once you get it working, go read about bind addresses on the mysql website and set it appropriately.

    2) Create an new account user@ipaddr where user is the new username and IPAddress is the ip4 address of the computer your trying to connect from. i.e.:

    CREATE USER 'user'@'192.168.1.68' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.68';
    

    Now try accessing mysql through the terminal program using the new username on the computer with the ip you entered above by typing:

    mysql -uuser -ppassword -hx.x.x.x
    

    Hopefully, this will help point you in the right direction. There’s a ton of information about bind addresses and security on the web.

    Login or Signup to reply.
  3. Because the phpmyadmin container has connected to the default host localhost. But your mysql server is located in other container (it means you cannot connect to mysql server by using localhost). So in the phpmyadmin service, you have to set PMA_HOST=db. See full env variables: https://hub.docker.com/r/phpmyadmin/phpmyadmin/

    Full docker-compose.yml:

    version: '3'
    
    services:
     web: 
      image: nginx:alpine
      ports:
       - 80:80
      volumes:
       - ./public_html:/public_html
       - ./conf.d:/etc/nginx/conf.d
      networks:
       - nginxphp
    
     php:
      image: php:7.1.11-fpm-alpine
      volumes:
       - ./public_html:/public_html
      expose:
       - 9000
      networks:
       - nginxphp
    
     db:
      image: mysql
      environment:
       MYSQL_ROOT_PASSWORD: root
      ports:
       - "3306:3306"
     phpmyadmin:
      image: phpmyadmin/phpmyadmin
      environment:
        PMA_HOST: db
        MYSQL_ROOT_PASSWORD: root 
        MYSQL_USER: root
        MYSQL_PASSWORD: root
      depends_on:
       - db
      ports:
       - "8080:80"
    
    networks:
        nginxphp:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search