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
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
Hope this will save some time to someone!
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:
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.:
Now try accessing mysql through the terminal program using the new username on the computer with the ip you entered above by typing:
Hopefully, this will help point you in the right direction. There’s a ton of information about bind addresses and security on the web.
Because the
phpmyadmin
container has connected to the default hostlocalhost
. But your mysql server is located in other container (it means you cannot connect to mysql server by using localhost). So in thephpmyadmin
service, you have to setPMA_HOST=db
. See full env variables: https://hub.docker.com/r/phpmyadmin/phpmyadmin/Full docker-compose.yml: