1

I have around 200 database all managed under cpanel phpmyadmin. I need to make similar edits to each of this operation. (2 SQL statements)

I would like to know how do i execute the queries so that it can alter the tables all in all the 200 database. (is there a feature to alter all dbs )

Have no issue executing the queries, however i feel it is inefficient as what i am doing now is to click into each db and execute the sql for that db -> have to do 200+ times.

2
  • 2
    200 databases? That sounds a lot. Are you sure it's not 200 tables in a database?
    – Grigor
    Commented May 21, 2012 at 17:27
  • yes! its 200 databases, not tables
    – Slay
    Commented May 21, 2012 at 17:46

2 Answers 2

2

You could develop either a stored procedure or a php script to build up dynamic queries and execute them on the fly.

1

Good question, you can do following:

// Connect to your mysql server
mysql_connect(...);

// Execute command which gets you list of all database from mysql server
$rs = mysql_query("SHOW DATABASES");

// Loop through all of them and execute your sql statements;
while ( $ds = mysql_fetch_assoc($rs) )
{

    mysql_select_db( $ds['Database'] );
    $sql = "some sql";
    mysql_query($sql);
}

I think something like above should serve the purpose.

1
  • Thank you for the code snippet. I just updated my 200 databases with a click. :)
    – Slay
    Commented May 21, 2012 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.