How to run a MySQL query using the command line:
-e to execute the command. Here is what that will look like:
mysql -u -p -e "create database database_name"
Here is another more complex example. In this case a query needed to be created to reset a CRON that synchronized with a foreign system. We needed to override this query on a regular basis.
mysql -uusername -ppassword database_name -e "update domains set registrar='abc' where domain not like '%net.za' and domain not like '%web.za' and domain not like '%co.za' and domain not like '%.org.za' and registrar = 'xyz'"
The beauty of these one liners is you can easily add them as a cron, e.g.: