Run SQL Query from Command Line

Document created by Anson McCook Expert on Nov 16, 2015Last modified by Anson McCook Expert on May 8, 2017
Version 4Show Document
  • View in full screen mode

There may be a need to run a sql query from an SSH session as opposed to running the query in the user interface.

This can be helpful for data manipulation as this type of export doesn't include any graphical headers or formatting included in the user interface export.

Follow the steps below to run a sql query from the command line.

1) SSH into a Turbonomic instance, root credentials (root/vmturbo).


2) Navigate to the tmp directory:


cd /tmp/


3) Run the following command, replacing the red text with your SQL query and the blue text with the name of your file. For examples of SQL queries, refer to the Reports forum.

**If your SQL query contains single quotes ('), you'll need to replace them with double quotes ("). This can be accomplished quickly with any text editor.**


mysql -uroot -pvmturbo vmtdb -e 'INSERT_SQL_QUERY' > sqlresult.csv



4) SCP into the Turbonomic appliance, navigate to the /tmp direcotry and save the csv file to your local machine.

5) When opening for the first time, the data may appear in one single column. Set the correct delimiter to view the information in columns.

6) In Excel, highlight the entire column (Column A) and go to Data > Text to Columns

Choose "Delimited" and Next

Choose "Tab" as the delimiter. Verify in the preview that the data is now being separated. Click Finish.


6) Your report should now be nicely organized into the appropriate columns.

3 people found this helpful