Given a configuration option name, returns the option value from the sys_config
table, or the provided default value (which may be NULL
) if the option does not exist in the table.
If sys_get_config()
returns the default value and that value is NULL
, it is expected that the caller is able to handle NULL
for the given configuration option.
By convention, routines that call sys_get_config()
first check whether the corresponding user-defined variable exists and is non-NULL
. If so, the routine uses the variable value without reading the sys_config
table. If the variable does not exist or is NULL
, the routine reads the option value from the table and sets the user-defined variable to that value. For more information about the relationship between configuration options and their corresponding user-defined variables, see Section 28.4.2.1, “The sys_config Table”.
If you want to check whether the configuration option has already been set and, if not, use the return value of sys_get_config()
, you can use IFNULL(...)
(see example later). However, this should not be done inside a loop (for example, for each row in a result set) because for repeated calls where the assignment is needed only in the first iteration, using IFNULL(...)
is expected to be significantly slower than using an IF (...) THEN ... END IF;
block (see example later).
in_variable_name VARCHAR(128)
: The name of the configuration option for which to return the value.
in_default_value VARCHAR(128)
: The default value to return if the configuration option is not found in the sys_config
table.
Get a configuration value from the sys_config
table, falling back to 128 as the default if the option is not present in the table:
mysql> SELECT sys.sys_get_config('statement_truncate_len', 128) AS Value;
+-------+
| Value |
+-------+
| 64 |
+-------+
One-liner example: Check whether the option is already set; if not, assign the IFNULL(...)
result (using the value from the sys_config
table):
mysql>SET @sys.statement_truncate_len =
IFNULL(@sys.statement_truncate_len,
sys.sys_get_config('statement_truncate_len', 64));
IF (...) THEN ... END IF;
block example: Check whether the option is already set; if not, assign the value from the sys_config
table:
IF (@sys.statement_truncate_len IS NULL) THEN SET @sys.statement_truncate_len = sys.sys_get_config('statement_truncate_len', 64); END IF;