#### 28.4.5.19 The sys\_get\_config() Function

[]()[]()

 Given a configuration option name, returns the option value from the [`sys_config`](sys-sys-config.html) table, or the provided default value (which may be `NULL`) if the option does not exist in the table.

 If [`sys_get_config()`](sys-sys-get-config.html) 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()`](sys-sys-get-config.html) 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`](sys-sys-config.html) 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”](sys-sys-config.html).

 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).

##### Parameters

* `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.

##### Return Value

 A `VARCHAR(128)` value.

##### Example

 Get a configuration value from the [`sys_config`](sys-sys-config.html) 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`](sys-sys-config.html) 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`](sys-sys-config.html) table:

```
IF (@sys.statement_truncate_len IS NULL) THEN
  SET @sys.statement_truncate_len = sys.sys_get_config('statement_truncate_len', 64);
END IF;
```

