Install Stored Procedure on Multiple Databases

前端 未结 3 953
眼角桃花
眼角桃花 2021-01-22 10:38

Is there any way to easily create a stored procedure on multiple MySQL databases at once? All the databases are on the same MySQL install.

3条回答
  •  死守一世寂寞
    2021-01-22 11:07

    Assuming you are using Linux, a simple BASH loop with an array of schema names will let you do this.

    Save your procedure definition to a file (e.g. myproc.sql), then use the file as input to mysql in the loop. If you put your sign-in details in ~/.my.cnf you can also avoid having to put usernames and passwords on the cmdline.

    for i in dbname1 dbname2 dbname3; do mysql ${i} < myproc.sql; done;
    

提交回复
热议问题