Access denied for mysql docker image in bamboo - mysql

I've got this configuration for a MySQL Docker image:
mysqldata:
image: busybox
volumes:
- /var/lib/mysql
mysql:
image: mysql:5.6
ports:
- "8203:3306"
volumes_from:
- mysqldata
environment:
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_USER=root"
and I lift it up with docker-compose up -d mysql, and I can run commands against the DB in the image, access it without problems, etc.
Then I setup a docker image to be lifted in Bamboo:
But it fails when running commands against the DB in that image, with the error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
From the build logs of the test run I can see that the env variables are applied:
/usr/bin/docker run --workdir /data --detach --name mysql-user-service -p 8203:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_USER=root mysql:5.6
But still no success.
Anyone knows how to overcome this problem?

Where are you connecting from? The host, another container?
Did you give permissions to the user#localhost MySQL user so it has access to the database? That error usually means the user you are connecting with doesn't have access to the db, and you need to grant the permissions.
If you do a docker ps you will see the name and the ID of the container you started for MySQL. Take that name or ID and run
docker exec -it <name or id> sh
That will get you into the container and you can run your MySQL commands to grant access something like this.
GRANT ALL ON *.* TO 'root'#'localhost
Since you are using compose you can do something like this as well
docker-compose run mysql GRANT ALL ON *.* TO 'root'#'localhost
You might also have to create the database of there isn't one already, and you would use the same steps just change the sql that is run

Related

Logging in to phpmyadmin - docker

Hi i am having trouble logging into phpmyadmin on localhost port 8080.
These are the steps i have carried out:
Running an sql container
~$ docker run -d mysql/mysql-server
I then use docker logs to get the generated password.
I ran this command to enter sql:
$ docker exec -it ce9a316 mysql -uroot -p
I then changed the password with this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'mysql-password';
I then run my phpadmin and link this container to the sql
docker run --name phpmyadmin -d --link ce9a316046f0:db -p 8080:80 phpmyadmin
I am then trying to login to phpmyadmin on port 8080 with username: root and the password set above but it wont let me login. any help is much appricated.
This command fixed the issue:
CREATE USER 'root'#'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%';

Unable to connect to mysl container via HeidiSQL via localhost

Environment:
I've created and started a Docker container on Windows 11 via the following command:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
Then I've created a new HeidiSQL session with the following options:
library: libmysql.dll
host: 127.0.0.1
user: root
password: root
port: 3306
After click on Open it says "Can't connect to MySQL server on '127.0.0.1' (10061)".
I'am able to connect to the container via the terminal.
After some research and some experiment I am able to find a solution.
First of all the port fordwarding must be forced to be 3306:3306.
You must create and run the Docker container with the parameter -p 3306:3306.
docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
Now the error is changed, but at least it can connect to the server.
"Access denied for user 'root'#'172.17.0.1' (using password: YES)"
Now most solutions found on the web tells to create a new user 'root'#'172.17.0.1' and grant all privileges to the user.
But, even after creating the user, HeidiSQL is unable to login again (same "access denied" error).
The strange thing is that if you login with the new user with a terminal, and then, try to login with HeidiSQL, now it works, this happens everytime you restart the container.
After searching I found this: https://github.com/HeidiSQL/HeidiSQL/issues/980
So the problem is that libmysql.dll is outdated and not supported, and it fails everytime you try to access for the first time with HeidiSQL.
You must switch to libmariadb.dll that is also compatible with mysql, is not needed to create the new user.
Do not use libmysql-6.1.dll, because crashes and not works for some reasons...

Connect to laravel sail mysql from macOS local machine

I have installed a fresh Laravel 8 Project using sail
https://laravel.com/docs/8.x/installation#getting-started-on-macos
I followed the guide. First ran this
curl -s "https://laravel.build/example-app" | bash
Then this
./vendor/bin/sail up
But now I have difficulty connecting using mysql client. This is the command that I'm trying to execute
mysql -u sail -D example_app -h localhost -P 3306 -p
I get the following error
ERROR 1045 (28000): Access denied for user 'sail'#'localhost' (using password: YES)
The .env file at the root of the project – docker-compose.yml automatically detects and imports the content of this file. For instance, in the MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' line, the container's MYSQL_ROOT_PASSWORD environment variable will receive the value of DB_PASSWORD from the .env file.
By default these are sail for the username and password for the pass. Are you passing that password when connecting?
This is a really good article i followed to get more insights: https://tech.osteel.me/posts/you-dont-need-laravel-sail
Use DB_HOST as 'mysql' in .env file.

MySQL with docker Access denied

I need to use MySQL on docker. The steps I've followed :
Installed docker
Pulled MySQL docker image
Ran docker container for MySQL
Installed MySQL client.
But When I run this
sudo docker exec -it mysql8 MySQL -uroot -p
It asks for a password, I enter the password and it gives me this :
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password : Yes)
How do I fix this and what am I missing?
I followed the tutorial here :
https://www.techrepublic.com/article/how-to-deploy-and-use-a-mysql-docker-container/
In order to create a docker container for mysql, you can use this command given below.
docker run -e MYSQL_ROOT_PASSWORD=password -e MYSQL_USER=user -e MYSQL_PASSWORD=password -d -p 3308:3306 -v $HOME/docker/volumes/mysql:/var/lib/mysql mysql
You can also set more environment variables for mysql in this given command.
In order to access mysql inside this container you have 2 easy ways:
Use docker exec -it container_name. Then write mysql -u root -p inside the container or along with the command given is your wish.
Use mysql client and access from local itself.
The article you have followed is outed and also running container and the change password is not the proper way when working in the container. With Offical image, you can set using environment variable.
use below command and further details you can find on Mysql Docker hub.
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mypass -d mysql
then try to connect
docker exec -it some-mysql bash -c "mysql -u root -pmypass"
Found the answer.
Have to run
docker logs <container_name>
which gives a generated password using which we have to use when prompted for password.
Afterward, we can change the password by :
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';

Accessing a MySql database from external IP (Docker containers)

Using Docker containers, I am trying to access a MySQL Docker container (https://hub.docker.com/_/mysql/) from other containers.
To do that, I've been using the PhpMyAdmin docker container (https://hub.docker.com/r/phpmyadmin/phpmyadmin/) which is the most simple way to view mysql databases.
Access denied
However... my phpmyadmin container cannot connect to the mysql container, giving the following error :
#1045 - Access denied for user 'root'#'172.17.0.7' (using password:
YES)
This is the config I have used for the mysql container:
docker run --name mysql001 -v /path/to/volumes/mysql001:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=1234 -p 33067:3306 -d mysql/mysql-server:latest --character-set-server=utf8 --collation-server=utf8_general_ci
The phpmyadmin configuration is:
docker run --name phpmyadmin1 -d --link mysql001:db -p 3949:80 phpmyadmin/phpmyadmin --env MYSQL_ROOT_PASSWORD=1234
Failed attempts
I've tried to log on in bash mode with docker exec -i mysql001 bash and run mysql commands from here, but each time I try for example to do mysql -u root -p so I get rejected with "Access denied for user 'root'#'localhost'"
What did I miss?