Unable to connect to mysl container via HeidiSQL via localhost - mysql

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...

Related

Intellij Connect to Docker MySQL DB

I have a problem connecting to a docker mysql DB through the Intellij UI.
I am able to connect using the following command through the terminal:
mysql -h localhost -P 3306 --protocol=tcp -u root -p db_name --password=password
Note the user of the --protocol flag, without this I could not connect. In addition, I assume that since I can connect through the terminal to the docker DB then setup is correct, i.e. the port is exposed and I am able to connect.
In Intellij I use the following connection settings - I am not sure where you specify the protocol of the connection, in case this resolved the issue. I've also tried using 127.0.0.1 instead of localhost which as I read will use the tcp protocol. But no luck.
I've tried the latest MYSQL Driver (8) for the connection as well as the MySQL for 5.1 version.
The error I get is the following(though the password and username are triple checked, and I am able to connect through the terminal):
The specified database user/password combination is rejected:
[28000][1045] Access denied for user 'root'#'localhost' (using
password: YES)
Any help or guidance would be much appreciated.

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.

docker can't connect to mariadb from localhost with different user

Hi I have followed this docker tutorial for mariabdb and also checked this stackoverflow question as well. I can start to mariadb container without any issues and can connect with root and mypass password with command mysql -h0.0.0.0 -uroot -pmypass. However, after I create a new user and grant all on it, I am not able to connect with that specific username and password. I am getting access denied error.
Here is the docker ps command output;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
268c36eac13a mariadb/server:10.3 "docker-entrypoint.s…" 31 minutes ago Up 31 minutes 0.0.0.0:3306->3306/tcp mariadbtest
I connect to mariadb container with docker exec -it 268c36eac13a /bin/sh and run these commands;
mysql -uroot -pmypass
create database emails;
grant all on emails.* to 'testUser'#'localhost' identified by '123456';
Then, from localhost when I am run mysql -h0.0.0.0 -utestUser -123456 I am getting Access denied for user 'testUser'#'172.17.0.1' (using password: YES) error.
Thanks for help!
I think this is a problem with networking : you allow user testUser to connect to your database from localhost but this means he will be able to connect only from client running inside the container. As you can see when you are logging to your MariaDB container from host machine you get your host docker address 172.17.0.1.
One solution is to allow your user to connect from any ip :
grant all on emails.* to 'testUser'#'%' identified by '123456';
or IP from given subnet. You can check how to do it in CREATE USER docs.
Another solution would be to add user for IP of host machine. You can get the host IP from within the container and add user for this IP. On how to get host IP from the container check this question.

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?

Access denied for mysql docker image in bamboo

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