MySQL Shell can print results in table, tabbed, or vertical
format, or as pretty or raw JSON output. From MySQL Shell 8.0.14,
the MySQL Shell configuration option
resultFormat
can be used to specify any of
these output formats as a persistent default for all sessions, or
just for the current session. Changing this option takes effect
immediately. For instructions to set MySQL Shell configuration
options, see Section 13.4, “Configuring MySQL Shell Options”.
Alternatively, the command line option
--result-format
or its aliases
(--table
,
--tabbed
,
--vertical
) can be used at startup
to specify the output format for a session. For a list of the
command line options, see Section A.1, “mysqlsh — The MySQL Shell”.
If the resultFormat
configuration option has
not been specified, when MySQL Shell is in interactive mode, the
default format for printing a result set is a formatted table, and
when MySQL Shell is in batch mode, the default format for
printing a result set is tab separated output. When you set a
default using the resultFormat
configuration
option, this default applies in both interactive mode and batch
mode.
The MySQL Shell function shell.dumpRows()
can
format a result set returned by a query in any of the output
formats supported by MySQL Shell, and dump it to the console.
(Note that the result set is consumed by the function.)
To help integrate MySQL Shell with external tools, you can use
the --json
option to control JSON
wrapping for all MySQL Shell output when you start MySQL Shell
from the command line. When JSON wrapping is turned on,
MySQL Shell generates either pretty-printed JSON (the default) or
raw JSON, and the value of the resultFormat
MySQL Shell configuration option is ignored. When JSON wrapping
is turned off, or was not requested for the session, result sets
are output as normal in the format specified by the
resultFormat
configuration option.
The outputFormat
configuration option is now
deprecated. This option combined the JSON wrapping and result
printing functions. If this option is still specified in your
MySQL Shell configuration file or scripts, the behavior is as
follows:
With the
json
orjson/raw
value,outputFormat
activates JSON wrapping with pretty or raw JSON respectively.With the
table
,tabbed
, orvertical
value,outputFormat
turns off JSON wrapping and sets theresultFormat
configuration option for the session to the appropriate value.