you can also use expect...such as: #!/<path_to_binary>/expect spawn mysql -u root -p expect "password:" send "password\r" expect "mysql>" send "use db1" expect "mysql>" send "alter table ...\r" expect "mysql>" send "exit\r" expect eof also, since expect uses the tcl language, you could create a tcl list with your database names...here's the reworked script: #!/<path_to_binary>/expect set x [list db1 db2 db3 dbN] spawn mysql -u root -p expect "password" send "password\r" foreach db $x { expect "mysql>" send "use $db\r" expect "mysql>" send "alter table ...\r" } expect "mysql>" send "exit\r" expect eof if you wanted to reuse the script w/ different database names every time, you could modify the script to accept database names as parameters...to do this, delete the creation of the tcl list and on the foreach line above...then, instead of referencing the a list you created in the "foreach" statement, you would use the following line: foreach db $argv { } this will iterate through the list of parameters you pass when you invoke the script...hope all this helps! "Thalis A. Kalfigopoulos" wrote: > On Thu, 5 Apr 2001, Santiago LLobet wrote: > > > Hi,... > > > > We've got a MySQL server running with a lot of different databases that have the >same table-structure. > > > > Does anybody knows how to make an SCRIPT that performs an administrative task >(like ALTER TABLE 'table_name') in all the databases? > > > > Do I have to use a script like this ? > > > > USE database1; > > ALTER TABLE users ..... ; > > USE database2; > > ALTER TABLE users......; > > USE database3; > > . > > . > > . > > > > (Actually the USE command does not work) > > > > Thanks a lot to all the people in the list!!!! :-) > > I don't see why you'd have an administrative script to perform ALTER commands. Not >my idea of a batch job. Anyway, why don't you just give th DB name on the ALTER line: > ALTER TABLE dbname.tablename... > You write the script and execute it as: > mysql -u root -p < lala.sql > > regards, > thalis > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
--------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php