简体   繁体   English

一次在多个数据库中执行MySQL查询

[英]Execute MySQL query in multiple databases at once

I have many MySQL databases that have same tables with the same structure. 我有许多MySQL数据库,它们的表具有相同的结构。 I am looking for simple way how can I alter table structure in all of 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, 一种QND方式,但无论如何,

  • make changes on main-db with prefered tool. 使用首选工具在main-db上进行更改。
  • copy successful sql-statement to web-script (php or similar) that executes the sql with loop on defined 'slave' dbs. 将成功的sql语句复制到Web脚本(php或类似文件),该脚本在定义的“从属”数据库上执行带循环的sql。

//regards //问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM