views:

217

answers:

1

Hello.

I've written all of MySQL procedures as root@localhost. Code looks like :

CREATE DEFINER=`root`@`localhost` PROCEDURE `p_add_user`(...)

Trouble is, when deploying on online server. When I replace root with current user and replace localhost with current IP, it works just fine. But that is quite annoyance ....

Is there any way, how to write procedures in more abstract way? So someone who will use my database and procedures would not have to edit "root" and "localhost" words?

Thanx

+2  A: 

As stated in MySQL documentation here

CREATE
[DEFINER = { user | CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body

So, the DEFINER part is not mandatory, just CREATE PROCEDURE should work.

maid450
It says "The DEFINER clause determines the security context to be used when checking access privileges at trigger activation time. More detail is given later in this section."So when I make sure, procedures are used only by privileged users, I can totally remove whole definer things?
Xorty
Yes, I suppose. I think that when you define user's permissions there is a "execute procedures" privilege that can be granted/denied (no sure about that...)
maid450
Good, I'll try it later and respond back if it worked. Thanx
Xorty
It worked, thanx :)
Xorty