管理 MySQL Shell 配置選項

abce發表於2024-06-20

與任何工具一樣,MySQL Shell 的開箱即用配置可能無法滿足每個使用者在任何情況下的需求。我們需要一種方法來輕鬆檢視、更新和持續(如有必要)更改預設配置。有一條命令可以幫助我們管理 MySQL Shell 配置。這條命令就是 \option。

檢視幫助

 MySQL  localhost  JS > \option
NAME
      \option - Allows working with the available shell options.

SYNTAX
      \option [args]

DESCRIPTION
      The given [args] define the operation to be done by this command, the
      following values are accepted

      - -h, --help [<filter>]: print help for the shell options matching
        filter.
      - -l, --list [--show-origin]: list all the shell options.
      - <shell_option>: print value of the shell option.
      - <shell_option> [=] <value> sets the value for the shell option.
      - --persist causes an option to be stored on the configuration file.
      - --unset resets an option value to the default value, removes the option
        from configuration file when used together with --persist option.

EXAMPLES
      \option --persist defaultMode sql

      \option --unset --persist defaultMode

列出配置選項

 MySQL  localhost  JS > \option -l
 autocomplete.nameCache          true
 batchContinueOnError            false
 connectTimeout                  10
 credentialStore.excludeFilters  []
 credentialStore.helper          default
 credentialStore.savePasswords   prompt
 dba.connectTimeout              5
 dba.connectivityChecks          true
 dba.gtidWaitTimeout             60
 dba.logSql                      0
 dba.restartWaitTimeout          60
 defaultCompress                 false
 defaultMode                     none
 devapi.dbObjectHandles          true
 history.autoSave                false
 history.maxSize                 1000
 history.sql.ignorePattern       *IDENTIFIED*:*PASSWORD*
 history.sql.syslog              false
 interactive                     true
 logFile                         /root/.mysqlsh/mysqlsh.log
 logLevel                        5
 logSql                          error
 logSql.ignorePattern            *SELECT*:SHOW*
 logSql.ignorePatternUnsafe      *IDENTIFIED*:*PASSWORD*
 mysqlPluginDir                  /usr/local/mysql-shell-8.0.37-linux-glibc2.28-x86-64bit/lib/mysql/plugins
 oci.configFile                  /root/.oci/config
 oci.profile                     DEFAULT
 outputFormat                    table
 pager                           ""
 passwordsFromStdin              false
 resultFormat                    table
 sandboxDir                      /root/mysql-sandboxes
 showColumnTypeInfo              false
 showWarnings                    true
 ssh.bufferSize                  10240
 ssh.configFile                  ""
 useWizards                      true
 verbose                         0
 MySQL  localhost  JS >

更新配置

語法格式:

\option {option name} {value}
或者
\option {option name=value}

例如,將verbose從 0 更改成 4:

 MySQL  localhost  JS > \option verbose
0
 MySQL  localhost  JS > \option verbose=4
 MySQL  localhost  JS > \option verbose
4
 MySQL  localhost  JS > 

使用以上更改方式,只是對當前會話有效。

更新持久化

語法格式:

\option --persist {option name=value}

在 版本 8.4之前,mysql shell 預設是使用js模式啟動;自 8.4 開始,預設是以 sql 模式開啟。

 MySQL  localhost  JS > \option defaultMode
none
 MySQL  localhost  JS > \option --persist defaultMode=js
 MySQL  localhost  JS > \option defaultMode
js
 MySQL  localhost  JS > \option --persist defaultMode=sql
 MySQL  localhost  JS > \option defaultMode
sql
 MySQL  localhost  JS > 

檢查值的來源

語法格式:

\option -l --show-origin

例如:

  MySQL  localhost  JS > \option -l --show-origin
 autocomplete.nameCache          true (Compiled default)
 batchContinueOnError            false (Compiled default)
 connectTimeout                  10 (Compiled default)
 credentialStore.excludeFilters  [] (Compiled default)
 credentialStore.helper          default (Compiled default)
 credentialStore.savePasswords   prompt (Compiled default)
 dba.connectTimeout              5 (Compiled default)
 dba.connectivityChecks          true (Compiled default)
 dba.gtidWaitTimeout             60 (Compiled default)
 dba.logSql                      0 (Compiled default)
 dba.restartWaitTimeout          60 (Compiled default)
 defaultCompress                 false (Compiled default)
 defaultMode                     sql (User defined)
 devapi.dbObjectHandles          true (Compiled default)
 history.autoSave                false (Compiled default)
 history.maxSize                 1000 (Compiled default)
 history.sql.ignorePattern       *IDENTIFIED*:*PASSWORD* (Compiled default)
 history.sql.syslog              false (Compiled default)
 interactive                     true (Compiled default)
 logFile                         /root/.mysqlsh/mysqlsh.log (Compiled default)
 logLevel                        5 (Compiled default)
 logSql                          error (Compiled default)
 logSql.ignorePattern            *SELECT*:SHOW* (Compiled default)
 logSql.ignorePatternUnsafe      *IDENTIFIED*:*PASSWORD* (Compiled default)
 mysqlPluginDir                  /usr/local/mysql-shell-8.0.37-linux-glibc2.28-x86-64bit/lib/mysql/plugins (Compiled default)
 oci.configFile                  /root/.oci/config (Compiled default)
 oci.profile                     DEFAULT (Compiled default)
 outputFormat                    table (Compiled default)
 pager                           "" (Compiled default)
 passwordsFromStdin              false (Compiled default)
 resultFormat                    table (Compiled default)
 sandboxDir                      /root/mysql-sandboxes (Compiled default)
 showColumnTypeInfo              false (Compiled default)
 showWarnings                    true (Compiled default)
 ssh.bufferSize                  10240 (Compiled default)
 ssh.configFile                  "" (Compiled default)
 useWizards                      true (Compiled default)
 verbose                         4 (User defined)
 MySQL  localhost  JS > 

可以看到,很多值都是 Compiled default,有些是來自配置檔案。

恢復模式設定

如果我們更改了配置,並希望將值恢復為預設值,我們可以使用以下語法將選項恢復為預設值。

語法格式:

\option --unset {option name}
或者
\option --unset --persist {option name}

例如:

 MySQL  localhost  JS > \option defaultMode
sql
 MySQL  localhost  JS > \option --unset --persist defaultMode
 MySQL  localhost  JS > \option defaultMode
none
 MySQL  localhost  JS > 

相關文章