If you want to automate MySQL installation or schedule a backup, it is necessary to run MySQL query directly from a Bash script using the following syntax:
mysql -u [user] -p[pass] << EOF [mysql commands] EOF |
Example:
#!/bin/bash mysql -u [user] -p[pass] << EOF USE mysql; DESC user; SELECT Host,User,Password FROM user; EOF |