Understanding the sys.sys_get_config() Function in MySQL

In MySQL, we can use the sys.sys_get_config() function to get a configuration option value from the sys_config table.

Syntax

The syntax goes like this:

sys.sys_get_config( in_variable_name, in_default_value )

Where in_variable_name is the configuration option name, and in_default_value is a default value that’s returned if the given option does not exist in the sys_config table.

Example

Here’s an example to demonstrate:

SELECT sys.sys_get_config( 'ps_thread_trx_info.max_length', NULL );

Result:

65535

In this case, the option exists in the sys_config table and so its value is returned.

Non-Existing Option

Here’s an example of passing an option that doesn’t exist:

SELECT sys.sys_get_config( 'oops', 'N/A' );

Result:

N/A

So the second argument is used as the default value.

Passing the Wrong Number of Arguments

Passing the wrong number of arguments results in an error:

SELECT sys.sys_get_config( 'ps_thread_trx_info.max_length' );

Result:

ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.sys_get_config; expected 2, got 1

We get the same error if we omit the arguments altogether:

SELECT sys.sys_get_config( );

Result:

ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.sys_get_config; expected 2, got 0