Stored Routines and MySQL Privileges
1696
• When a database is dropped, all stored routines associated with it are dropped as well.
(In MySQL 5.0.0, stored routines are global and not associated with a database. They inherit the
default database from the caller. If a
USE db_name
is executed within the routine, the original default
database is restored upon routine exit.)
Stored functions cannot be recursive.
Recursion in stored procedures is permitted but disabled by default. To enable recursion, set the
max_sp_recursion_depth
[472]
server system variable to a value greater than zero. Stored
procedure recursion increases the demand on thread stack space. If you increase the value of
max_sp_recursion_depth
[472]
, it may be necessary to increase thread stack size by increasing
the value of
thread_stack
[500]
at server startup. See
Section 5.1.4, “Server System Variables”
, for
more information.
MySQL supports a very useful extension that enables the use of regular
SELECT
statements (that
is, without using cursors or local variables) inside a stored procedure. The result set of such a query
is simply sent directly to the client. Multiple
SELECT
statements generate multiple result sets, so the
client must use a MySQL client library that supports multiple result sets. This means the client must
use a client library from a version of MySQL at least as recent as 4.1. The client should also specify
the
CLIENT_MULTI_RESULTS
option when it connects. For C programs, this can be done with the
mysql_real_connect()
C API function. See
Section 20.6.6.52, “
mysql_real_connect()
”
, and
Section 20.6.15, “C API Support for Multiple Statement Execution”
.
18.2.2. Stored Routines and MySQL Privileges
Beginning with MySQL 5.0.3, the grant system takes stored routines into account as follows:
• The
CREATE ROUTINE
[576]
privilege is needed to create stored routines.
• The
ALTER ROUTINE
[576]
privilege is needed to alter or drop stored routines. This privilege is
granted automatically to the creator of a routine if necessary, and dropped from the creator when the
routine is dropped.
• The
EXECUTE
[577]
privilege is required to execute stored routines. However, this privilege is granted
automatically to the creator of a routine if necessary (and dropped from the creator when the routine
is dropped). Also, the default
SQL SECURITY
characteristic for a routine is
DEFINER
, which enables
users who have access to the database with which the routine is associated to execute the routine.
• If the
automatic_sp_privileges
[437]
system variable is 0, the
EXECUTE
[577]
and
ALTER
ROUTINE
[576]
privileges are not automatically granted to and dropped from the routine creator.
• The creator of a routine is the account used to execute the
CREATE
statement for it. This might not
be the same as the account named as the
DEFINER
in the routine definition.
The server manipulates the
mysql.proc
table in response to statements that create, alter, or drop
stored routines. It is not supported that the server will notice manual manipulation of this table.
18.2.3. Stored Routine Metadata
Metadata about stored routines can be obtained as follows:
• Query the
ROUTINES
table of the
INFORMATION_SCHEMA
database. See
Section 19.8, “The
INFORMATION_SCHEMA ROUTINES
Table”
.
• Use the
SHOW CREATE PROCEDURE
and
SHOW CREATE FUNCTION
statements to see routine
definitions. See
Section 13.7.5.8, “
SHOW CREATE PROCEDURE
Syntax”
.
• Use the
SHOW PROCEDURE STATUS
and
SHOW FUNCTION STATUS
statements to see routine
characteristics. See
Section 13.7.5.26, “
SHOW PROCEDURE STATUS
Syntax”
.
•
INFORMATION_SCHEMA
does not have a
PARAMETERS
table until MySQL 5.5, so applications that
need to acquire routine parameter information at runtime must use workarounds such as parsing
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...