use mysql functions for multiple databases with same pattern name

1k views Asked by At

Can I import Mysql function and use it for multiple database with same pattern name without import that function any more ?

I know Mysql save function in two table :

information_schema.ROUTINES and mysql.proc

Does anyone have an idea to do this?

1

There are 1 answers

0
Ravinder Reddy On

Every stored procedure is associated with its schema or database.
So long as the SPs are just routines but not depended on table data, one can happily call them from anywhere.

And if the SPs are intended to calculate based on table data, then you definitely need that database qualifier while defining the SP body.
I.e. instead of calling
select count(*) from routines;,
you require to call
select count(*) from information_schema.routines;.

If you look into the table structure of both routines and proc you can find a column routine_schema and db respectively which point to target database of the SPs.

Unless you define SP bodies, which are table data related, in this way you definitely have to redefine them in your database environment.

More important thing is that, you again require privileges to access and execute such cross database SPs.