How do you run a single query through mysql from the command line?

Matthew picture Matthew · Oct 21, 2009 · Viewed 141.8k times · Source

I'm looking to be able to run a single query on a remote server in a scripted task.

For example, intuitively, I would imagine it would go something like:

mysql -uroot -p mydb_production "select * from users;"


RC. picture RC. · Oct 21, 2009
mysql -u <user> -p -e "select * from schema.table"