首页 > 解决方案 > MySQL Workbench:启动时自动连接到数据库

问题描述

目前,我必须:

  1. 启动 MySQLWorkBench 8.0
  2. 单击我需要连接的数据库 在此处输入图像描述

我想:

  1. 启动 MySQLWorkBench 8.0
  2. MySQLWorkBench 自动连接到该数据库,无需我点击它

我需要在一天中重新打开 MySQLWorkbench,因此想消除这一步。

标签: mysqlmacosmysql-workbench

解决方案


我的第一个想法是:如果您经常需要它,请不要关闭它。

但是,如果您愿意从脚本运行 MySQL Workbench,则很容易实现您想要的。例如/Application在终端中打开并运行此命令(在 macOS 上):

open -a MySQLWorkbench.app --args --query "Localhost 8.0"

其中“Localhost 8.0”必须更改为您要打开的连接名称。这将打开该服务器的 SQL IDE。您可以将调用放入 shell 脚本并运行它而不是应用程序本身。

而不是--query用于--help打印支持的命令列表:

MySQLWorkbench [<options>] [<name of a model file or sql script>]
Options:
    --admin <instance>            Open a administration tab to the named instance
    --configdir <path>            Specify configuration directory location, default is platform specific.
    -h, --help                    Show help options   
    --log-level <level>           Valid levels are: error, warning, info, debug1, debug2, debug3
    --log-to-stderr               Also log to stderr  
    --migration                   Open a migration wizard tab
    --model <model file>          Open the given EER model file
    --open                        Open the given file at startup (deprecated, use script, model etc.)
    --query <connection>|<connection string>Open a query tab and ask for connection if nothing is specified.
If named connection is specified it will be opened,
else connection will be created based on the given connection string,
    --quit-when-done              Quit Workbench when the script is done
    --run <code>                  Execute the given Python code
    --run-python <code>           Execute Python code from a file
    --run-script <file>           Execute Python code from a file
    --script <sql file>           Open the given SQL file in an connection, best in conjunction with a query parameter
    --upgrade-mysql-dbs           Open a migration wizard tab
    -v, --verbose                 Enable diagnostics output
    --version                     Show Workbench version number and exit

但是,这在使用命令时不显示任何输出open(由于它的工作方式,另请参阅如何在控制台上获取 os x 应用程序的输出,或到文件?),但您可以运行该应用程序直接二进制(而不是上面显示的应用程序包),如下所示:

./MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench --help 

推荐阅读