Execute MySQL queries from Command Line

Writing by on Monday, 10 of March , 2014 at 9:00 pm

If say, you want to capture the results of MySQL query into a file, you might want to run use the command line option (-e) to execute the SQL query.

You can follow the syntax:
mysql -uuser -ppassword database -equery_to_execute

# Show on stdout
$ mysql -uuser -ppassword database -e ‘show tables’

# Redirect to a file
$ mysql -uuser -ppassword database -e ‘show tables’ > tables.txt

Leave a comment

Category: SQL DB

No Comments

No comments yet.

Leave a comment

You must be logged in to post a comment.

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.