0

I have multiple databases all having the same table structure on one server. I need to change three tables in all databases which name is

xx_databasename

where xx is an isoAlpha2Code of the country the database os connected to.

So how can I perform a query like

DROP TABLE IF EXISTS tablename;
CREATE TABLE tablename (....);

on each database with just one mySQL command?

Thallius
  • 2,482
  • 2
  • 18
  • 36
  • Is that multiple databases all within ONE INSTANCE of MySQL? – RiggsFolly Nov 17 '21 at 13:24
  • Yes all on one instance and server – Thallius Nov 17 '21 at 13:25
  • check this solution out: [link](https://stackoverflow.com/questions/43622691/delete-table-across-multiple-databases). I think it will solve the problem – Ibrahim Hammed Nov 17 '21 at 13:27
  • 2
    You cannot do all three databases in one command, but you can do `DROP TABLE IF EXISTS DB1.tablename;` and then `DROP TABLE IF EXISTS DB2.tablename;` etc etc This assumes that the user account you are logged in with will work and allow whatever command you try and execute on all 3 databases – RiggsFolly Nov 17 '21 at 13:27

0 Answers0