I'd like to archive the results of a series of query EXPLAIN plans into a table for later analysis.
I created a table that contains all the fields from an EXPLAIN result, but I can't figure out how to populate it from executing an EXPLAIN command.
I figured out how to export a .sql file in MySQL Workbench that contains INSERT commands, but I have to edit this manually to make it work. Is the EXPLAIN information stored somewhere so I could write queries to do it automatically? I can't find it in either the information_schema or performance_schema.
Best Answer
If you are running on
Linux OS
you could save it into a file.Example:
On command line run:
mysql -e
will execute the query on the command line.tee -a
will read from standard input and write to filetest.txt
And you'll get:
You can use
perl
to replace the death lines to any delimiter you want (I used comma in this example).Example:
Hope this help.