Search code examples
mysqlmysql-workbenchddev

Specify a particular database query from command line with MySQL Workbench


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?


Solution

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