I think what is needed here is a small perl program that

does a "show databases"
and then
pseudo code Q&D:

#!/bin/perl -w
use MySql;
$command = $ARGV[0];

$dbh=MySql->connect('mysql','localhost');
$sth=$dbh->query('show databases');
while ($db=$sth->fetchrow) {
  `$command`;
}


Martin Hubert
Freightgate - New Dimensions in e-Logistics (sm)
Visit us at http://www.freightgate.com
Email: [EMAIL PROTECTED]
Phone: +714.799.2833 Fax: +714.799.0100

-----Original Message-----
From: Thalis A. Kalfigopoulos [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 05, 2001 8:50 PM
To: Santiago LLobet
Cc: [EMAIL PROTECTED]
Subject: Re: SCRIPTS IN DIFFERENTS DATABASES


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

Reply via email to