Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql command line: execute two queries at once?

I am using the MySql command tool to query a database from inside a Ruby script I wrote. However the need has arisen for a query that creates a temporary table, then in another query I need to perform a join on the temporary table. The only problem is every time I invoke mysql -h <host> -r <username> -D <database> -e "QUERY" I get a new transaction, so when I am trying to perform my join, the temporary table doesn't exist anymore.

Is there anyway to do execute two separate queries in one invocation of the mysql command line tool??

Something like: mysql -h <host> -r <username> -D <database> -e "QUERY1" -e "QUERY2"

Or is there some alternative way to store my queries? like in a text file or something?

Thanks

like image 938
Hunter McMillen Avatar asked Apr 10 '26 04:04

Hunter McMillen


1 Answers

Wouldn't the ";" do the trick?

mysql -h <host> -r <username> -D <database> -e "QUERY1;QUERY2"

like image 154
Binus Avatar answered Apr 11 '26 17:04

Binus