mysql中 routine

huayang183發表於2020-10-27
1、如果使用者有create routine 許可權那麼他就可以建立procedure | function 。

2、如果使用者建立了procedure | function 那麼mysql 會自動賦予它對procedure | function 的alter routine和execute 許可權。

3、例子:

使用者root使用者建立一個spuser@'localhost'使用者並對它賦予create procedure 許可權




grant create routine on tempdb.* to spuser@'localhost' identified by '123456';

用spuser@'localhost'使用者去建立一個routine




delimiter go

create procedure sp_hello_world()

begin

  select 'hello world';

end

go

 

delimiter ;

再一次檢視spuser@'localhost'的許可權




mysql> show grants;

+---------------------------------------------------------------------------------------------------------------+

| Grants for spuser@localhost                                          |

+---------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'spuser'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |

| GRANT CREATE ROUTINE ON `tempdb`.* TO 'spuser'@'localhost'                          |

| GRANT EXECUTE, ALTER ROUTINE ON PROCEDURE `tempdb`.`sp_hello_world` TO 'spuser'@'localhost'          |

+---------------------------------------------------------------------------------------------------------------+

 

相關文章