How can the (JSON) formatted results from MySQL Shell be saved to a file?
1
vote
1
answer
3123
views
Somewhat uniquely among official MySQL applications, MySQL Shell offers (easy) JSON output. From the MySQL shell prompt, typing the following will get you results as a JavaScript array of objects (one for each row):
\option resultFormat json/array
\use information_schema
SELECT table_catalog, table_schema, table_name, engine, create_time, table_collation
FROM tables
WHERE table_schema='INFORMATION_SCHEMA' AND table_name LIKE 'T%';
This is then passed to a pager for display on-screen. How can the output instead be redirected or otherwise saved to a file (named e.g. results.json)?
(Note: the query could be anything. The above is provided as a simple, yet not trivial, test case that should be runnable against any MySQL installation.)
As MySQL Shell is available on various platforms, platform agnostic solutions are preferred, but solutions for specific platforms are also of interest.
Asked by outis
(375 rep)
Nov 6, 2021, 03:11 AM
Last activity: Nov 11, 2021, 10:23 AM
Last activity: Nov 11, 2021, 10:23 AM