Connect PHPMyAdmin/MySQL-Workbench to MySQL container (Docker) - mysql

I'm trying to connect to MySQL (inside a Docker container), through MySQL Workbench and PHPMyAdmin with no luck. I keep receiving the same error everytime I try to log in with both applications.
PhpMyAdmin error.png
I've also tried to deploy both containers with this docker-compose.yml:
version: '2.0'
services:
db:
image: mysql
environment:
- MYSQL_DATABASE=mysqltest
- MYSQL_USER=user
- MYSQL_PASSWORD=userpassword
- MYSQL_ROOT_PASSWORD=rootpassword
ports:
- "127.0.0.1:3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- "127.0.0.1:8080:80"
...and again, no luck!
Do you have any suggestion,please?

Solved.
Basically, it was a version problem. With the latest version of MySQL (I think it's 8) there are some problem if I try to connect through Workbench or PHPMyAdmin.
So, I've tried to use an older version of MySQL (version 5) and I've created two containers with these commands:
docker run --name mysql_test -e MYSQL_DATABASE=dbtest -e MYSQL_USER=user -e MYSQL_PASSWORD=userpassword -e MYSQL_ROOT_PASSWORD=rootpassword -p 127.0.0.1:3306:3306 -d mysql:5
docker run --name myadmin -d --link mysql_test:db -p 127.0.0.1:8080:80 phpmyadmin/phpmyadmin
So I managed to log in successfully, using both credentials that I've created as environment variables.
Hope this can help somebody!

Related

Can't change credentials (root, neither other user) via environment variables using docker compose command

This is how I start MySQL docker container from docker-compose.yml:
version: '3.9'
services:
mysql_db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root123
MYSQL_USER: my_user_1
MYSQL_PASSWORD: pwd_1
restart: always
volumes:
- db_vol:/var/lib/mysql
ports:
- "3306:3306"
- "33060:33060"
volumes:
db_vol:
The password for root is NOT changed => the default pwd: "root" for user root works.
Leave alone creating the other MYSQL_USER: user_1 with his password.
I can view the server status via for instance MySQL Workbench using default creds: root/root
The server status is green - running and when I click the Users and Privileged pane, this is what I see:
So there is another user1, instead of my_user_1 which I have created.
HOWEVER: When I run the container from cmd line like this:
docker run -d --rm -p 3306:3306 -p 33060:33060 -e
MYSQL_ROOT_PASSWORD=root123 --name=mysql_db mysql:latest
This also works even for user deli1
docker run -d --rm -p 3306:3306 -p 33060:33060 -e
MYSQL_ROOT_PASSWORD=root123 -e MYSQL_USER=deli1 -e
MYSQL_PASSWORD=deli_pwd --name=mysql_db mysql:latest
I do not want to use config files (shared via docker volumes to the container) to override default parameters of MySQL container. Instead, I'd like to use handy environment variables, which I read all around that works nice.. What could be I doing wrong ?
Ubuntu 22.04.1 using VSCode Version: 1.75.1
Date: 2023-02-08T21:35:30.018Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Linux x64 5.15.0-60-generic
Sandboxed: No

Docker Compose: Import MySQL database into a running docker container from CLI

After trying various things whatever I do I get certain error messages - I want to import a local SQL file database into a running docker container.
This is what I try to do:
sudo docker-compose exec project-db mysql -uuser -ppassword database_name < "/localpath/2020-05-03-14_00-hexagon_brainformance.sql"
This is my docker compose file:
db:
image: mysql:5.7.25
container_name: "project-db"
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'root'
ports:
- 3306:3306
volumes:
This is what sudo docker ps gives me:
cb2c5e884c90 mysql:5.7.25 "docker-entrypoint.s…" 19 hours ago Up 3 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp project-db
This is my current error:
ERROR: No such service: project-db
Tried various variations with using db instead of project-db and also with -it flag to go into the container first. What am I doing wrong?

Can't connect mysql docker to Drupal docker

I'm following the instructions here https://hub.docker.com/_/drupal
I ran $ docker run --name some-drupal -d drupal just fine
and I ran
`docker run -d --name some-mysql --network some-network \
-e MYSQL_DATABASE=drupal \
-e MYSQL_USER=user \
-e MYSQL_PASSWORD=password \
-e MYSQL_ROOT_PASSWORD=password \
mysql:5.7`
just fine as well. But when I go through the drupal install script in the browser, when I get to the database connection. The connection throughs an error. I've tried user as the user and root as the user, either way I get this same error. Not sure if I need to connect more ports to the containers but The instruction make it sound like this should work. What am I missing?
Docker can only resolve containers hostname to each other when they are on the same custom network.
Your mysql container are in network some-network as you show here:
docker run -d --name some-mysql --network some-network ...
When you start the drupal container you'll need to do the same:
docker run --name some-drupal -d --network some-network drupal
I recommend using docker-compose.yml file with Dockerfileif needed.
For example, this is the contents of docker-file.yml:
version: '3.9'
services:
SOME_DRUPAL_NAME:
image: drupal
restart: always
ports:
- 80:80
- 443:80
depends_on:
SOME_MYSQL_NAME
environment:
SOME_VARS: SOME_VALUE
SOME_MYSQL_NAME:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somedrupal
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
networks:
default:
external:
name: SOME_NETWORK_NAME
volumes:
SOME_NAME: {}
After having this file edited, run this command:
docker network create SOME_NETWORK_NAME
Also see Drupal environment variables for connecting Drupal to MySQL to add in docker-compose.yml file.
At last and when all things are done, run this:
docker-compose -f /to/your/docker-compose/file/docker-compose.yml up -d
Or if you're in the same path as docker-compose.yml:
docker-compose up -d
Then it should work.

MySQL commands inside Docker container

I have the following docker compose:
version: '3.1'
services:
db:
image: mysql:5.5
container_name: mysql
environment:
- MYSQL_ROOT_PASSWORD=some_root_pw
- MYSQL_DATABASE=some_db
- MYSQL_USER=db_user
- MYSQL_PASSWORD=user_pw
ports:
- 8306:3306
volumes:
- ./db:/var/lib/mysql/some_db
I am accessing the container with the command:
docker-compose exec db /bin/sh
Which drops me at the shell as expected. However, I am unable to access mysql with the information from the docker-compose file.
mysql -u root -p
Prompts for the password, then rejects for bad username or password. I have tried with both root and user. Is there a way I can troubleshoot what is happening with user creation?
NOTE: intentionally older version of MySQL.

TeamCity failed to connect MySQL which is run in Docker

I start MySQL in docker by using below command:
docker run --name mysql-for-teamcity \
-e MYSQL_ROOT_PASSWORD=FAKE-ROOT-PW\
-v ~/MySQL/var_lib_mysql:/var/lib/mysql \
-p 3306:3306 \
-p 33060:33060 \
-it mysql
But TeamCity failed to connect the MySQL, the error message is :
I can connect to the MySQL in Terminal using below command:
mysql -u root --protocol=tcp -p
And database "teamcity" has also been created.
My Environment:
Mac OS X 10.14.1
Docker Desktop 2.0.0.0-mac81(29211)
TeamCity and MySQL are running in seperated Docker containers
Both Docker images tag is latest
The reason is TeamCity and MySQL are running in the separate containers, so when I specified "127.0.0.1" for TeamCity, it is not possible for it to connect to MySQL. Because they are simply not running in the same host.
The solution is using Docker Compose which set up a local network for containers by default.
Step 1: create a docker-compose.yml in an empty directory you want to place your TeamCity:
version: '3'
services:
TeamCity:
image: jetbrains/teamcity-server
ports:
- "8111:8111"
volumes:
- <your TeamCity dir>/data:/data/teamcity_server/datadir
- <your TeamCity dir>log:/opt/teamcity/logs
MySQL:
image: mysql
ports:
- "3306:3306"
volumes:
- <your TeamCity dir>/mysql:/var/lib/mysql
env_file:
- mysql.env
Step 2: create a mysql.env in the same directory:
MYSQL_ROOT_PASSWORD=YOUR-MYSQL-PASSWD
Step 3: run docker-compose up -d in the terminal in
Step 4: open "http://127.0.0.1:8111" in browser
Step 5: input "MySQL:3306" in the DataBase Host field.