Monthly Archives: March 2012

MySQL Linux CLI command execution

As another aid to my memory, you can run mysql commands on the command line like this:

mysql -u user -p[password] database -e "SELECT * FROM orders;".

 

You can also send the mysql client commands on stdin:

echo "SELECT * FROM orders" | mysql -u user -p[password] database

 

Or read them in with a file redirection

mysql -u user -p[password] database < /home/kirrus/orders.sql

That last one is really handy for reading MySQL dumps back into MySQL.