MySQL :: MySQL 5.7 Reference Manual :: 4.5 Using mysql in Batch Mode
When using mysql in batch mode you can use pipes to write an interactive but pre-scripted shell script. Be aware that you need to use the "-n" command line option to flush the buffer otherwise your read will hang. Here is a code sample in ksh:...