Dimitrios Markopoulos Dimitrios Markopoulos - 5 months ago 12x
PHP Question

bulk create table in many databases in same server

I would like to ask whether there is some way to add a table with same schema to multiple databases in the same server and if it is possible to add e.g. a column to a specific table again in many databases that exist in same server. Is there some query for that or is it impossible?


For table creation:

select group_concat(
  concat('create table `', db.schema_name, '`.X (a int, b int);') separator '\n'
) as qry
from information_schema.schemata db
where db.schema_name in ('test', 'test_db');

Created result:

create table `test`.X (a int, b int);
create table `test_db`.X (a int, b int);

Copy the result and execute.

Same way you can create a bulk ALTER query.