开发者

Execute MySQL query in multiple databases at once

开发者 https://www.devze.com 2023-01-23 03:27 出处:网络
I have many MySQL databases that have same tables with the same structure. I am looking for simple way how can I alter table structure in all o开发者_如何学JAVAf the databases at once ( in one query o

I have many MySQL databases that have same tables with the same structure. I am looking for simple way how can I alter table structure in all o开发者_如何学JAVAf the databases at once ( in one query or using one tool).


you can see this solution like of alter many tables in the post :

select concat( 'alter table ', a.table_name, ' add index `fields` (`field`);' )
from information_schema.tables a 
where a.table_name like 'table_prefix_%';


A QND way, but anyhow,

  • make changes on main-db with prefered tool.
  • copy successful sql-statement to web-script (php or similar) that executes the sql with loop on defined 'slave' dbs.

//regards

0

精彩评论

暂无评论...
验证码 换一张
取 消