CREATE [AGGREGATE] FUNCTION function_name
RETURNS {STRING|INTEGER|REAL|DECIMAL}
SONAME shared_library_name;
This is the declaration for a User Defined Function, which appears to be what you are trying to install. This is not declaring a Stored Function. CREATE FUNCTION
has two different uses in MySQL. This is one of them.
For this to work:
- you do not need the
CREATE ROUTINE
privilege - it does not matter what database you're in, because User-Defined Functions, unlike stored functions, are global in scope. They extend MySQL functionality in a way that is analogous to its built-in aggregate functions, like
AVG()
andSUM()
andMIN()
andMAX()
. - you cannot specify a database as part of the function declaration
- the following is the requirement that you are missing:
13.7.3.1. CREATE FUNCTION Syntax for User-Defined Functions
To create a function, you must have the
INSERT
privilege for the mysql database. This is necessary becauseCREATE FUNCTION
adds a row to themysql.func
system table that records the function's name, type, and shared library name.— http://dev.mysql.com/doc/refman/5.6/en/create-function-udf.html
If you don't have this privilege, the function will have to be installed by someone who holds this privilege, or it will need to be granted to you. You can't grant it to yourself.