Mar 27, 2012
tom

How to create one update query (mysql) on multiple databases

Question

I have several DBS on the same mysql server.
The DBS’s structure and schema are exactly the same (only data is different)

the query on certain db works well like this (written in phpmyadmin)

UPDATE  `mdl_modules` SET `visible`=0 
WHERE `name` IN ("survey","feedback","audio","testing")

I thought it could be something like that:

UPDATE `db_name1`.`mdl_modules`, `db_name2`.`mdl_modules`,`db_name3`.`mdl_modules`
SET `visible`=0  WHERE `name` 
IN ("survey","feedback","audio","testing")

but this doesn’t work and I get an error
of course I have more that 3 dbs..

Thanks

Asked by Miki A

Answer

Use transactions.

START TRANSACTION;
  UPDATE  `db_name1`.`mdl_modules` SET `visible`=0 
    WHERE `name` IN ("survey","feedback","audio","testing");
  UPDATE  `db_name2`.`mdl_modules` SET `visible`=0 
    WHERE `name` IN ("survey","feedback","audio","testing");
  UPDATE  `db_name3`.`mdl_modules` SET `visible`=0 
    WHERE `name` IN ("survey","feedback","audio","testing");
COMMIT;
Answered by Janne Pikkarainen

Related posts:

  1. Best Mysql DB Engine When Insert update delete query is not made
  2. Are there any pitfalls with having multiple MySQL databases on 1 server node?
  3. How can artificially create a slow query in mysql?
  4. Multiple databases on Mysql crashes the mysql server often
  5. Create a SharePoint Survey from an Excel spreadsheet

Leave a comment