【问题标题】:MySQL Workbench: Connecting to database automatically on the startupMySQL Workbench:启动时自动连接到数据库
【发布时间】:2019-08-09 22:02:07
【问题描述】:

目前,我必须:

  1. 启动 MySQLWorkBench 8.0
  2. 点击我需要连接的数据库

我想:

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

我每天都需要重新打开 MySQLWorkbench,因此想取消这一步。

【问题讨论】:

    标签: mysql macos mysql-workbench


    【解决方案1】:

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

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

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

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

    使用--help 代替--query 来打印支持的命令列表:

    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 命令时,这不会显示任何输出(由于它的工作方式,另请参阅How to get the output of an os x application on the console, or to a file?),但您可以直接运行应用程序二进制文件(而不是如图所示的应用程序包上),像这样:

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

    【讨论】:

    • 非常感谢您的解决方案!正如我第一次看到命令工作,如果 Workbench 已经运行 args 将被忽略。除非我将应用程序作为新实例运行。有什么方法可以启动我对当前实例的查询?
    • MySQL 工作台仅在启动时解析命令行参数,因此您不能使用带有新参数的正在运行的实例。
    • 嘿@MikeLischke。我运行以下命令,它会打开应用程序并连接到数据库:"C:\..\MySQLWorkbench.exe" --query testdb 但是当我添加--script C:\..\23.10.20.sql--open C:\..\23.10.20.sql 时,它们不起作用。我只让应用程序连接到数据库。我将它们组合在一起:"C:\..\MySQLWorkbench.exe" --query testdb --script C:\..\23.10.20.sql 这是组合它们的正确方法吗?我在这里问了这个问题,但没有人回答:stackoverflow.com/questions/64595764/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 2011-04-06
    • 2016-07-28
    • 2018-11-29
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多