0

I would like to facilitate opening a database UI for development projects (usually docker containers, bound to arbitrary ports on the host machine) by a generic command.

I wonder if it is possible to open MySQL Workbench and let it connect automatically from the command line.

Similar to giving connection parameters with the mysql console:

mysql --host=127.0.0.1 --port=$port --user=db --password=db db

I haven't found that specifically in the supported arguments, so either it is hidden or maybe possible with any of the other options?

EDIT: Probably the way is to generate a file to pass to --query dynamically?

rfay
  • 9,963
  • 1
  • 47
  • 89
Jonas Eberle
  • 2,835
  • 1
  • 15
  • 25
  • Thank you for your comment. I've seen that already. How would my command look like to open a DB on port localhost:49155? – Jonas Eberle Sep 08 '21 at 15:15
  • Well I dont know, I never tried it, but if I wanted to, I would do just that. Try something and if it does not work, read the manual again, and try something else. Bit like developing really, try try until yo succeed – RiggsFolly Sep 08 '21 at 15:17
  • Cant find a way to pass the password, so all this may be in vain – RiggsFolly Sep 08 '21 at 15:28
  • How did you set the port generically? Have you generated the query file dynamically? – Jonas Eberle Sep 08 '21 at 19:51
  • `[64bit] MySQL5.7.28` is the name of a connection that exists already in my WorkBench. I use WAMPServer so I have many versions of MySQL and mariaDB that I could be using so I have amny canned connections in WorkBench – RiggsFolly Sep 09 '21 at 09:30

1 Answers1

1

Here's the format for the mysqlworkbench --query parameter:

--query="$user:$password@$host:$port"

This feature already exists as an example in ddev - look in the ~/.ddev/commands/host/mysqlworkbench.example file. (See on github).

For ddev, the query is set up as query="root:root@127.0.0.1:${DDEV_HOST_DB_PORT}", which uses the root/root credentials, accesses the 'db' container via localhost on the port provided by ddev at $DDEV_HOST_DB_PORT.

rfay
  • 9,963
  • 1
  • 47
  • 89