You can run MySQL commands from the terminal by using -e switch. Here are a few examples.

<pre lang="bash">
mysql -u username -p -e "create database mydb"
mysql -u username -p -e "use mydb"
mysql -u username -p database -e "select * from mytable"

If you have .mycnf configured, you can omit the username and password.

<pre lang="bash">
mysql -e "create database mydb"
mysql -e "use mydb"
mysql -e "select * from mytable"

To run multiple commands from a single line, separate the commands using a semicolon.

<pre lang="bash">
mysql -e "create database somedb; use mydb; select * from mytable;"