How to Run a Mysql Query from Command Line and Write the Output into a File
search cancel

How to Run a Mysql Query from Command Line and Write the Output into a File

book

Article ID: 36871

calendar_today

Updated On:

Products

CA Infrastructure Management CA Performance Management - Usage and Administration

Issue/Introduction

SUMMARY

Usually people run MySQL query from the MySQL prompt, but it's a common practice to run it from command line and write the output into a file. This article provides the steps for doing it.

 

ENVIRONMENT

 

CA Performance Management (all versions)

All supported platforms

 

INSTRUCTIONS

  1. On the CAPC system, move into the mysql bin directory
    cd /opt/vertica/MySQL/bin.

  2. Run a MySQL query from the command line and write the sql output into a file.

 

Here is an example of a sql statement (between the double quotes) run from the command line; netqosportal.dst_device is the database name and table name.

mysql -e "select SourceID,ItemID,ItemName,Model from netqosportal.dst_device;" > /tmp/output.txt

 

Below is what the file content looks like

cat /tmp/output.txt

SourceID       ItemID       ItemName             Model
3       117     Sim23571:CGYLAB_C881.allstream.com
3       116     Sim24077:brlb-cmts-2    BSR64000
3       118     Sim24593:NetScaler      Citrix NetScaler
3       115     DataAggregator:10.130.153.96    NULL
3       114     IMDC1RH65       NULL
5       305     marjo46-rtr-01.ca.com   NULL
6       357     cis2524-blue-96.26.ca.com       NULL
6       355     cis2514-96.24   NULL
6       356     cis3640-96.25.153       NULL
6       350     cis7505-96.10.10.ca.com NULL
6       353     cis3810-96.13.ca.com    NULL
6       361     rs3000-green-96.30      NULL
6       360     rs3000-green-96.29-1411911752   NULL
6       349     cisco2621-96.7.ca.com   NULL
6       365     cis3750-183.6.ca.com    NULL
6       362     cis2524-cyan-96.31.ca.com       NULL
6       352     cis3810-96.12.ca.com    NULL
6       364     rs3000-PurpleCE1-96.39  NULL
6       351     cis7505-96.11.ca.com    NULL
6       354     cis3640-96.22.ca.com    NULL
6       366     rs3000-246.19   NULL
6       363     cis2811-96.32   NULL
6       348     cis7204-96.6.ca.com     NULL

 

 

 

 

 

 

 

 

 

 

 

 

 

Environment

Release: IMDAGG99000-2.5-Infrastructure Management-Data Aggregator
Component: