Docker create container mysql and can not connect this database - mysql

This is my Container Which Is I opened
db:
container_name: admin_db
image: mysql:8.0.27
environment:
MYSQL_DATABASE: admin
MYSQL_USER: root
MYSQL_PASSWORD: 12345
MYSQL_ROOT_PASSWORD: 12345
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33066:3306
networks:
- app
When I Run This Code
docker exec -it CONTAINER_ID mysql -uroot -p
It gives Such kind of Error, I entered this password 12345
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)

You should change the name of MYSQL_USER, this is used to specify a secondary user, if you use this config should work:
db:
container_name: admin_db
image: mysql:8.0.27
environment:
MYSQL_DATABASE: admin
MYSQL_USER: admin_db_user
MYSQL_PASSWORD: 12345
MYSQL_ROOT_PASSWORD: 12345
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33066:3306
networks:
- app

Related

not able to connect mysql from sequel or terminal

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

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

Run 2 docker mysql containers simultaneously with docker-compose

I need help setting up 2 mysql docker containers at the same time.
Right now I spin up my mysql docker container via docker-compose like this:
version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: my_database
MYSQL_USER: user
MYSQL_PASSWORD: ********
MYSQL_ROOT_PASSWORD: ********
MYSQL_ROOT_USER: root
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3308:3306'
What I've tried is copy-pasting the docker-composse.yml into a different folder and changing it a little
version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: my_other_database
MYSQL_USER: user
MYSQL_PASSWORD: ********
MYSQL_ROOT_PASSWORD: ********
MYSQL_ROOT_USER: root
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3310:3307'
I run docker-compose up for both of them and both start up normally. I can connect to port 3308 just fine but I cannot connect to port 3310. I get
Can not read response from server.
Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
How do I set up my docker-compose.yml files so I get 2 mysql containers that run simultaneously?
I think you have the wrong Port on the second config. Mysql runs on port 3306
Change 3310:3307 to 3310:3306.
The whole config:
version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: my_other_database
MYSQL_USER: user
MYSQL_PASSWORD: ********
MYSQL_ROOT_PASSWORD: ********
MYSQL_ROOT_USER: root
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3310:3306'

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.

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.