The MySQL Keyring +-------------------------------------------+ A return value of 1 indicates success. If the key cannot be created, the return value is  NULL  and an error occurs. One reason this might be is that the underlying keyring plugin does not support the specified combination of key type and key length; see Section 6.4.4.12, “Supported Keyring Key Types and Lengths” . To be able to check the return type regardless of whether an error occurs, use  SELECT ... INTO @ var_name  and test the variable value: mysql>  SELECT keyring_key_generate(’’, ’’, -1) INTO @x; ERROR 3188 (HY000): Function ’keyring_key_generate’ failed because underlying keyring service returned an error. Please check if a keyring plugin is installed and that provided arguments are valid for the keyring you are using. mysql>  SELECT @x; +------+ | @x | +------+ | NULL | +------+ mysql>  SELECT keyring_key_generate(’x’, ’AES’, 16) INTO @x; mysql>  SELECT @x; +------+ | @x | +------+ | 1 | +------+ mysql>  SELECT keyring_key_type_fetch(’MyKey’); +---------------------------------+ | keyring_key_type_fetch(’MyKey’) | +---------------------------------+ | DSA | +---------------------------------+ mysql>  SELECT keyring_key_length_fetch(’MyKey’); +-----------------------------------+ | keyring_key_length_fetch(’MyKey’) | +-----------------------------------+ | 256 | +-----------------------------------+ This technique also applies to other keyring functions that for failure return a value and an error. The ID passed to  keyring_key_generate()  provides a means by which to refer to the key in subsequent functions calls. For example, use the key ID to retrieve its type as a string or its length in bytes as an integer: To retrieve a key value, pass the key ID to  keyring_key_fetch() . The following example uses  HEX() to display the key value because it may contain nonprintable characters. The example also uses a short key for brevity, but be aware that longer keys provide better security: mysql>  SELECT keyring_key_generate(’MyShortKey’, ’DSA’, 8); +----------------------------------------------+ | keyring_key_generate(’MyShortKey’, ’DSA’, 8) | +----------------------------------------------+ | 1 | +----------------------------------------------+ mysql>  SELECT HEX(keyring_key_fetch(’MyShortKey’)); +--------------------------------------+ | HEX(keyring_key_fetch(’MyShortKey’)) | +--------------------------------------+ | 1DB3B0FC3328A24C | +--------------------------------------+ 1440