-1

I'm following guides in order to run a local MySQL database by using Docker, this link in particular: https://blog.christian-schou.dk/creating-and-running-a-mysql-database-with-docker-compose/

My MySQL is up since I can check state on console:

enter image description here

Here is the code for my docker-compose.yml file in order to set version and credencials

version: '3.8'

services:
  db:
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    ports:
      - "3306:3306"

And here my credentials files (I'm just testing, no security needed)

MYSQL_ROOT_PASSWORD=admin
MYSQL_DATABASE=admin
MYSQL_USER=admin
MYSQL_PASSWORD=admin

But I'm trying to access my local database by using Heidi Windows app and I get this error

enter image description here

It's very important for me to get access by using Heidi, since I have a lot of tables to create and data to import, and I prefer to do all that by using a graphical client, not command line, and yes, I work using Windows, is it a problem?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Windgate
  • 365
  • 1
  • 4
  • 14
  • What connection information are you using to connect to the database? This seems like you're starting a database and trying to connect to it with an administration tool; what is your programming-related question? Would using your application framework's database-migration and seed-data subsystems be more maintainable and reproducible? – David Maze Aug 06 '23 at 12:29
  • I suspect a DNS problem, so you can use `--skip_name_resolve` – Moshe L Aug 06 '23 at 12:29
  • @DavidMaze the connection information I'm using is the same listed on my cretentials code file, if they are set in the code file and if I can check database is up with Docker comands, I don't understand why I can not connect by using an administration tool, maybe I need to use any command or check any code file, is not my problem clear to you? Do you need anything more to explain it? – Windgate Aug 06 '23 at 13:29
  • @MosheL is that a command or a parameter for a command? As command is not found if used it on the same console I run docker commands, if it's a parameter please tell me to which command must I attach it to. – Windgate Aug 06 '23 at 13:30
  • If the administration tool is running directly on the host, it can't use the Docker networking, and the host name and port you need to connect to the container will often be different. – David Maze Aug 06 '23 at 13:58
  • Thanks @DavidMaze I have taked a look and used the command docker inspect 'ContainerID' Port is the same (3306) but I can't connect to the given IP 172.18.0.2, I keep on researching – Windgate Aug 06 '23 at 18:21
  • That IP address is basically totally useless. It only works at all on one very specific Docker configuration. Does [docker postgres pgadmin local connection](https://stackoverflow.com/questions/25540711/docker-postgres-pgadmin-local-connection) give you some useful hints? – David Maze Aug 06 '23 at 19:02

1 Answers1

0

Your problem is the username is by default admin@localhost but you are connecting from a remote machine with an IP (172.18.0.1).

You can use a init.sql file to create a new mysql user

https://iamvickyav.medium.com/mysql-init-script-on-docker-compose-e53677102e48

and add the query for create the user:

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Other option: you can connect to the commandline interface via

docker exec -it mysql bash -l
# login from local system
$> mysql -uadmin -padmin   

and then add a new user with access from the remote machine (e.g admin@%.

Moshe L
  • 1,797
  • 14
  • 19