views:

37

answers:

2

Hello there, I was wondering whether the following command (from a .bat script):

(1) connects to the mysql instance once and then executes script#1 followed by script#2, or (2) does it reconnect for each of the sql scripts?

mysql -B -b -h%HOST% -u%USER% -p%PASSWORD% %SCHEMA% < "scripts\create_and_populate.sql" < "scripts\update_joomla_article.sql"

I have a bad feeling it reconnects. If so, how would I go about changing the .bat script to execute one sql script after another without reconnecting. Cheers :)


Edit:

I only found out recently, to my great shame :-Z, that this command does not actually work as I expected.

mysql ... < script1 < script2 < script3 appeared to work at first, until I spotted that only the last script in the chain is actually executed. Still, I will welcome any suggestions as to How to get this done in a different way that what Colin Pickard suggested.

+1  A: 

You could maybe use a couple of scripts with SELECT CONNECTION_ID( ); to determine your theory, and then something like this:

copy scripts\create_and_populate.sql+scripts\update_joomla_article.sql scripts\temp\create_update.sql
mysql -B -b -h%HOST% -u%USER% -p%PASSWORD% %SCHEMA% < "scripts\temp\create_update.sql"
del scripts\temp\create_update.sql

(WARNING: I have not tested that! try it out first!)

Colin Pickard
thanks, this works like a charm. I did have the idea myself but I found it a bit too complex for a simple problem. I then thought that doing it like `mysql ... < script1 < script2 < script3` will work, and it appeared to work at first, until I spotted that only the last script in the chain is actually executed. Doing it as you suggested works perfectly. Thanks.
Peter Perháč
A: 

one more suggestion, does this work?

mysql -e script1 -e script2 -e script3
Colin Pickard