running mysql commands from the terminal
You can run MySQL commands from the terminal by using -e switch. Here are a few examples.
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.
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.
mysql -e "create database somedb; use mydb; select * from mytable;"