You are here: All articles » Programming » Execute multiple queries in one mysql command line
-
Execute multiple queries in one mysql command line
written: 9 years ago category: Programming Previous Next
On the command line, you may want to execute more than one SQL command at once. Most hints recommend a batch file to accomplish that, but that requires an additional file placed somewhere where you may forget it.
You can also fire several queries with the --execute parameter, separated by semicolon:
mysql -hlocalhost -uroot --execute"TRUNCATE dba.log_customer; TRUNCATE dba.log_quote; TRUNCATE dba.log_summary;"
...and the slightly shorter version:
mysql -hlocalhost -uroot -e"TRUNCATE dba.log_customer; TRUNCATE dba.log_quote; TRUNCATE dba.log_summary;"
Comments:
Leave a comment
Andrew King 6 years ago Permalink
Thanks! Im still trying to run multiple queries and have each result output to its own text fileAnsgar 6 years ago Permalink
I suppose you need to run separate command lines if you wish to have separate output files. Maybe there is some text-cut-and-put-into-files command line out there but I think that's not worth the effort. Or probably use the "SELECT ... INTO outfile" syntax - see the documentation on https://dev.mysql.com/doc/refman/8.0/en/select-into.html