Cannot log in to the MySQL server through browser - docker

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

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.

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:

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!

Related

Docker. Phpmyadmin does not see the port assigned to it

I am using the following docker configuration:
version: "3"
services:
database:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 1009
restart: "always"
phpmyadmin:
image: phpmyadmin
ports:
- "8080:80"
environment:
PMA_HOST: database
restart: "always"
depends_on:
- database
It works, but if I change the mysql port for my PC to - "3360:3306" (for example 3306 may be busy with the main mysql service running on the computer) - it stops working. If I do this, I will be able to connect to mysql from my computer in CMD like mysql -u root -P 3360 -p, but phpmyadmin will give the error - connection refused.
No matter what I do, I see this error. For example I used the following docker configuration:
version: "3"
services:
database:
image: mysql
networks:
- my-network
ports:
- "3360:3306"
environment:
MYSQL_ROOT_PASSWORD: 1009
restart: "always"
phpmyadmin:
image: phpmyadmin
links:
- database
networks:
- my-network
ports:
- "8080:80"
environment:
PMA_HOST: database
PMA_PORT: 3360
restart: "always"
depends_on:
- database
networks:
my-network:
Even all of this didn't work. Phpmyadmin gave out one inscription when trying to connect - Connection refused all the time. But it still worked in the terminal.
Why can't I use a different port for phpmyadmin in docker?

Unable to connect mysql after docker mysql created

I setup my docker mysql and phpadmin via
version: '3.2'
services:
mysqllocal:
image: mysql:8.0
container_name: container_mysqllocal
restart: always
ports:
- '6603:3306'
environment:
MYSQL_ROOT_PASSWORD: pass1234
MYSQL_ROOT_HOST: '%'
phpmyadmin:
depends_on:
- mysqllocal
image: phpmyadmin/phpmyadmin
container_name: container_phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: mysqllocal
UPLOAD_LIMIT: 3000000000
docker inspect container_mysqllocal and got '172.30.0.2'. However when I tried to connect mysql via SequelPro. It gives Connection Failed error. How do I connect mysql to my SequelPro / mysql workbench app, is there any configuration I've missed?
Below is the screenshot of my SequelPro connection:
have you tried to access mysql from your local machine with the port defined, in your config is 6603

Connection between docker containers as localhost

i am trying to dockerize my web application. i am running a apache webserver + mariadb and redis server as you can see in my docker-compose file combined with an nginx proxy to use local domains and ssl.
everything works fine as long is i use the container names to connect to mysql / redis. I dont want to change all localhosts in my code to the mysql / redis container names.
Is there a way to keep "localhost" as Host instead of the containers name?
version: "3.5"
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: portal-proxy
networks:
- portal
ports:
- "80:80"
- "443:443"
volumes:
- ./certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
portal:
image: portal:latest
container_name: portal-webserver
networks:
- portal
volumes:
- ./portal:/var/www/html/portal
links:
- db
restart: always
environment:
VIRTUAL_HOST: portal.dev
db:
image: mariadb:latest
container_name: portal-db
networks:
- portal
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: portal
MYSQL_USER: www-data
MYSQL_PASSWORD: www-data
MYSQL_ROOT_PASSWORD: asdf1234
volumes:
- ./db:/docker-entrypoint-initdb.d
- ./db:/var/lib/mysql
redis:
image: redis:latest
container_name: portal-redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
networks:
- portal
ports:
- "6379:6379"
networks:
portal:
name: portal
Use a common hostname (staging.docker.host) on all containers, that resolves to the docker host's ip 1.2.3.4.
So adding this to containers:
extra_hosts:
- "staging.docker.host:1.2.3.4"
and use that name (staging.docker.host) in all you connection endpoints.
On you local machine you also add (staging.docker.host) to your /etc/hosts or C:\Windows\System32\drivers\etc\hosts with localhost 127.0.0.1 staging.docker.host.

phpmyadmin can't connect to mariadb with docker-compose: Packets out of order

So whats wrong with this docker-compose.yml? It actually looks ok to me.
But when i try to log in to phpmyadmin on http://localhost:8080/index.php
i get errors:
Packets out of order. Expected 0 received 1. Packet size=71
mysqli_real_connect(): MySQL server has gone away
mysqli_real_connect(): Error while reading greeting packet. PID=33
mysqli_real_connect(): (HY000/2006): MySQL server has gone away
version: "3"
services:
db:
image: mariadb:10.4
volumes:
- test_db_data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: root
networks:
- dbtest
pma:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- 8080:80
environment:
- PMA_HOST=db
networks:
- dbtest
adminer:
image: adminer
restart: unless-stopped
ports:
- 8081:8080
networks:
- dbtest
volumes:
test_db_data:
networks:
dbtest:
Context:
Docker version 19.03.3
docker-compose version 1.23.2
Update:
I added adminer as well and login also fails.
Mysql stderr shows:
[Warning] Aborted connection 9 to db: 'unconnected' user: 'unauthenticated' host: '192.168.32.3' (This connection closed normally without authentication)
I had the same error and fixed it by deleting the database volume and recreating the database. Not the nicest of solutions. The MySQL server was getting stuck on startup.
I had the luck of it being a database on a dev box so running migrations and reseeding with test data was all I had to do.

Can't access Docker database using IP (only localhost)

I'm trying to setup Docker to allow connections from other devices on my network. Currently to access Docker I visit localhost on my computer. I'm trying to connect using my computer's local IP (192.168.0.140), which lets me see my files but not connect to my database.
I assume this is a problem with my configuration but I don't know enough about Docker to troubleshoot it.
version: '2'
services:
webserver:
build: ./docker/webserver
image: localdev
ports:
- '80:80'
- '443:443'
volumes:
- ./www:/var/www/html
links:
- db
db:
image: mysql:5.6
ports:
- 3306
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: secret
ports:
- '8080:80'
Any help would be greatly appreciated.
Maybe you should try like this :
version: '2'
services:
webserver:
build: ./docker/webserver
image: localdev
ports:
- '0.0.0.0:80:80' # Map container port 80 on your "public" ip on port 80, it will be available on the network
- '0.0.0.0:443:443' # Same for port 443
volumes:
- ./www:/var/www/html
links:
- db
db:
image: mysql:5.6
# ports:
# - 3306 # You don't need to map port 3306 because mysql already expose this port for others containers, unless you wan't to access to your mysql directly
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
#links:
# - db # Not necessary, with docker-compose v2 every containers are in the same network and see each other
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_ROOT_PASS
WORD: secret
ports:
- 'localhost:8080:80' # to keep your phpmyadmin only available from localhost.
The reason you are able to connect to the other containers is because you have mapped the ports between the container and the host.
For the database you are using the short port syntax:
ports:
- 3306
This will choose a random port on the host. To be able to connect to the database, use the long form syntax:
ports:
- '3306:3306'
In that case, you will be able to connect to the database on localhost:3306

Resources