not able to connect mysql from sequel or terminal - mysql

I'm using mysql in docker. I can access docker through docker exec terminal. But I can't access it outside through my regular terminal or sequel ace.
What I'm getting in in sequel ace and in regular terminal
Access denied
Unable to connect to host 127.0.0.1 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'crowdtank'#'localhost' (using password: YES)
Access denied for user 'crowdtank'#'localhost' (using password: YES)
Terminal command and output for access attempt
ERROR 1045 (28000): Access denied for user 'crowdtank'#'localhost' (using password: YES)
My docker code
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: crowdtank
MYSQL_USER: crowdtank
MYSQL_PASSWORD: crowdtank
MYSQL_ROOT_PASSWORD: crowdtank
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www
ports:
- "9000:9000"
networks:
- laravel

Related

phpipam docker cannot connect to database

This is the configuration for my docker container. I am getting the following error: Could not connect to database! SQLSTATE[HY000] [1045] Access denied for user 'root'#'172.18.0.4' (using password: YES)
# WARNING: Replace the example passwords with secure secrets.
# WARNING: 'my_secret_phpipam_pass' and 'my_secret_mysql_root_pass'
version: '3'
services:
phpipam-web:
image: phpipam/phpipam-www:latest
ports:
- "80:80"
environment:
- TZ=Europe/London
- IPAM_DATABASE_HOST=phpipam-mariadb
- IPAM_DATABASE_PASS=my_secret_phpipam_pass
- IPAM_DATABASE_WEBHOST=%
restart: unless-stopped
volumes:
- phpipam-logo:/phpipam/css/images/logo
depends_on:
- phpipam-mariadb
phpipam-cron:
image: phpipam/phpipam-cron:latest
environment:
- TZ=Europe/London
- IPAM_DATABASE_HOST=phpipam-mariadb
- IPAM_DATABASE_PASS=my_secret_phpipam_pass
- SCAN_INTERVAL=1h
restart: unless-stopped
depends_on:
- phpipam-mariadb
phpipam-mariadb:
image: mariadb:latest
environment:
- MYSQL_ROOT_PASSWORD=my_secret_mysql_root_pass
restart: unless-stopped
volumes:
- phpipam-db-data:/var/lib/mysql
volumes:
phpipam-db-data:
phpipam-logo:
I have tried logging into the docker container directly and was unable to access mysql through it. This did not work, so I tried using the mysqladmin within the docker container to access it but that did not work either.

How to connect phpmyadmin to mySql server with docker compose

I'm trying to reproduce a MAMP environment with Docker-Compose, but I can't connect the phpmyadmin service to my mariaDB database!
I have done a lot of testing, and nothing has been conclusive, at best phpmyadmin does not recognize user and password and I get the following message:
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'#'172.25.0.3' (using password: YES)
Here is the docker-compose file:
version: '3'
services:
php-apache:
build:
context: ./php-apache
container_name: cbx-webserver
ports:
- 80:80 # Le port dédié à ce service
restart: always
volumes:
- ./DocumentRoot:/var/www/html
links:
- mariadb
mariadb:
image: mariadb:10.1
container_name: db-mysql
ports:
- 3306:3306
restart: always
volumes:
- ./mariadb:/docker-entrypoint-initdb.d/
- mariadb:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_USER: root
MYSQL_HOST: mariadb
MYSQL_DATABASE: mydb
myadmin:
image: phpmyadmin/phpmyadmin:4.8.1
container_name: cbx-phpmyadmin
ports:
- 8081:80
restart: always
links:
- mariadb:mysql
environment:
PMA_HOST: mydb
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: root
depends_on:
- mariadb
volumes:
mariadb:
and the actual error message

Can not access to mysql through my docker container

I have mysql running through the docker, i.e. when I run the docker ps command, I get this result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fXX3aeXXcXXa mysql:5.7.22 "docker-entrypoint.s…" 35 minutes ago Up 18 minutes 0.0.0.0:3360->3306/tcp db
And here is my db service in my docker-compose.yml in my laravel root project:
# ... other services
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3360:3306"
environment:
MYSQL_DATABASE: laravel_db
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
- ./DockerDevelopment/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
# other services ...
So, I try this command: docker exec -it db bash then goes to my dockerized db command line, and I get this error:
root#fXX3aeXXcXXa:/# mysql -u root -p [ENTER]
Enter password: password
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
what should I do to be able to access mysql> in my docker?
Maybe you have to check your my.cnf. Maybe you can provide your config.
With this compose file the connect to mysql works:
version: "3"
services:
db:
image: mysql:5.7.22
container_name: dbvmssettlementiban
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: vms_settlement_iban
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
Let try:
mysql --protocol tcp --port=<your-mysql-port> -u root -p
OR
Add lines below to your my.cnf on client:
[client]
protocol=tcp
This works for my case.

How to fix "Access denied for user 'root'#'172.22.0.4' (using password: YES)" when connecting to mysql container?

I'm creating a laravel project in a docker container, along with MySQL and phpmyadmin, when trying to migrate (or access the database from phpmyadmin) I get access denied error.
I've tried several SOF solutions but none of them worked, also tried ones in GitHub issues.
here is my docker-compose.yml
version: "3"
services:
web:
container_name: ${APP_NAME}_web
build:
context: ./docker/web
ports:
- 9000:80
volumes:
- ./:/var/www/app
networks:
- mynet
db:
image: mysql:5.7
container_name: db
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laracocodb
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- mysqldata:/var/lib/mysql/
networks:
- mynet
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpma
links:
- db:db
ports:
- 9191:80
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
PMA_HOST: db
networks:
- mynet
networks:
mynet:
driver: bridge
volumes:
mysqldata:
driver: local
no matter where I access the database (from db container bash, from phpmyadmin index page or from the web service when trying to migrate the database), the error is always access denied
I have also run into this problem many times, by default MySQL allows root to be accessed by localhost user that means even if you have opened the port 3306:3306, you will still need to add the user.
Follow these commands and the error will resolve!
https://stackoverflow.com/a/11225588

docker phppyadmin container Access denied for user 'root'

I have installed docker on digitalocean droplet successfully and below shows my docker-compose.yml configurations:
version: '2.1'
services:
mysql:
build:
context: ./docker/mysql
image: mysql:latest
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root_pass
MYSQL_USER: root
MYSQL_PASSWORD: root_pass
volumes:
- mysqldata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- mysql:db
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root_pass
restart: always
ports:
- 8080:80
And once I up the docker services everything works fine as you can see by below screen capture.
And I can access my mysql database inside terminal perfectly with my user credentials.
But the problem is when I try to access phpmyadmin with droplet_ip:8080 its says:
#1045 - Access denied for user 'root'#'172.18.0.4' (using password: YES)
And here I used same username (root) password (root_pass) as well.
Any suggestions regarding this problem would be grateful. Thank you.
The following works for me
version: '3.1'
volumes:
mysql-volume:
services:
mysql:
image: mysql
container_name: mysql
volumes:
- mysql-volume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: supersecret
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_USER: user
MYSQL_PASSWORD: supersecret
ports:
- 80:80
depends_on:
- mysql
don't mix up root user and MySQL user. In my example above I use the MySQL user to login with phpadmin. if you want to login using your root user you don't have to specify MySQL user and it will look like this (you don't need to specify a user for phpmyadmin because it's always root):
version: '3.1'
volumes:
mysql-volume:
services:
mysql:
image: mysql
container_name: mysql
volumes:
- mysql-volume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: db
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: rootpass
ports:
- 80:80
depends_on:
- mysql
Also very important, remove your mysql volume when you want to recreate the whole setup. (docker volume rm ..). Because maybe your mysql is started with the same volume again after making changes.
I got the access denied error because I had a dollar sign in my password, which the docker compose file parses as variable substitution (I've only seen the ${} syntax) on this page you will read "Both $VARIABLE and ${VARIABLE} syntax are supported."
Therefore if I had for example this as my database password in the docker compose file: hello$world, the world variable would get substituted, of course I don't have a 'world' variable, the password that would be set in that case would be hello, so without knowing the docker compose syntax you would be trying to log in with hello$world, and you'd be denied access.