问题描述
我正在尝试重定向在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
解决方法
实现我的目标的一种方法是不使用mysqlsh
的“交互模式”,而是为每个语句打开一个新连接。
这不是我的首选方法,因为我猜这会为每个命令初始化一个新会话,但是它可以工作。
mysqlsh --uri root@localhost:3306/my_schema --sql --execute "select * from my_table;" --result-format=json/array > my_objects.json
我真的很有兴趣/感谢您提供更清洁的解决方案。