SHOW CREATE LIBRARY [database_name.]library_name
Returns the text that can be used to re-create the named JavaScript library in the named database; the database defaults to the current database if one is not specified. See Section 15.1.16, “CREATE LIBRARY Statement”, for more information.
For an account other than the account which created the library, access to routine properties depends on the privileges granted to the account, as described here:
With the
SHOW_ROUTINE
privilege or the globalSELECT
privilege, the account can see all library properties, including its definition. This means thatSHOW CREATE LIBRARY
prints the source code of the library, and all libraries in the Information Schemalibraries
table are visible to this account.With the
CREATE ROUTINE
,ALTER ROUTINE
, orEXECUTE
privilege granted at a scope that includes the library, the account can see all routine properties except its definition. This means that the associated row inINFORMATION_SCHEMA.LIBRARIES
is visible but,SHOW CREATE LIBRARY
does not print the library's source code.
Library code may contain SQL statements (known as a JavaScript
SQL callout). The statements are restricted, based on the
INVOKER
and DEFINER
security contexts of the stored program using that library. Such
SQL statements follow the usual restrictions applying to stored
functions and stored procedures (see
Section 27.9, “Restrictions on Stored Programs”).
mysql> SHOW CREATE LIBRARY jslib.lib1\G
*************************** 1. row ***************************
Library: lib1
sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,
NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Create Library: CREATE LIBRARY `lib1`
LANGUAGE JAVASCRIPT
AS $$
export function f(n) {
return n
}
$$
1 row in set (0.00 sec)
mysql> SHOW CREATE LIBRARY jslib.lib2\G
*************************** 1. row ***************************
Library: lib2
sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,
NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Create Library: CREATE LIBRARY `lib2`
LANGUAGE JAVASCRIPT
AS $$
export function g(n) {
return n * 2
}
$$
1 row in set (0.00 sec)
The SHOW CREATE LIBRARY
statement
was added in MySQL 9.2.0.
For further information and examples, see Section 27.3.8, “Using JavaScript Libraries”.