我正在尝试重定向在交互式环境中所做的语句的输出mysqlsh。
我在 OSX 上的终端内运行 mysqlsh,但在帮助页面中没有找到合适的参数来实现重新路由。通过默认的“pipe grep > and_run.txt”重新路由输出不起作用,因为 mysqlsh 环境有它自己的一组可接受的命令。
我的命令是:
:$ mysqlsh root@localhost:3306/my_schema
# now the mysqlsh interactive console is open with an active connection to my_schema
mysqlsh> shell.options.set('resultFormat','json')
mysqlsh> session.runSql("SELECT * FROM my_schema.my_table")
# prints the schema as json array - i would like to rerout this output
Run Code Online (Sandbox Code Playgroud)
实现我的目标的一种方法是不使用“交互模式”,mysqlsh而是为每个语句打开一个新连接。
这不是我的首选方法,因为我猜这会为每个命令初始化一个新会话,但它有效。
mysqlsh --uri root@localhost:3306/my_schema --sql --execute "select * from my_table;" --result-format=json/array > my_objects.json
Run Code Online (Sandbox Code Playgroud)
我真的很感兴趣/感谢更清洁的解决方案。