Documentation Home

5.7.1 表格格式

当 MySQL Shell 处于交互模式时,默认情况下使用表格格式打印结果集。查询结果显示为格式化表格,以便更好地查看和帮助分析。

要在批处理模式下运行时获得此输出格式,请使用 --result-format=table命令行选项(或其别名 --table)启动 MySQL Shell,或将 MySQL Shell 配置选项设置 resultFormattable.

示例 5.1 以表格格式输出

MySQL  localhost:33060+ ssl  world_x  JS > shell.options.set('resultFormat','table')
MySQL  localhost:33060+ ssl  world_x  JS > session.sql("select * from city where countrycode='AUT'")
+------+------------+-------------+---------------+-------------------------+
| ID   | Name       | CountryCode | District      | Info                    |
+------+------------+-------------+---------------+-------------------------+
| 1523 | Wien       | AUT         | Wien          | {"Population": 1608144} |
| 1524 | Graz       | AUT         | Steiermark    | {"Population": 240967}  |
| 1525 | Linz       | AUT         | North Austria | {"Population": 188022}  |
| 1526 | Salzburg   | AUT         | Salzburg      | {"Population": 144247}  |
| 1527 | Innsbruck  | AUT         | Tiroli        | {"Population": 111752}  |
| 1528 | Klagenfurt | AUT         | Kärnten       | {"Population": 91141}   |
+------+------------+-------------+---------------+-------------------------+
6 rows in set (0.0030 sec)