MySQL Shell 26.10  /  ...  /  Working with Credentials

4.4.2 Working with Credentials

The following functions enable you to work with the Pluggable Password store. You can list the available Secret Store Helpers, as well as list, store, and retrieve credentials.

var list = shell.listCredentialHelpers();

Returns a list of strings, where each string is a name of a Secret Store Helper available on the current platform. The special values default and <disabled> are not in the list, but are valid values for the credentialStore.helper option.

shell.storeCredential(url[, password]);

Stores credentials using the current Secret Store Helper (credentialStore.helper). The url argument must use the form user@(host[:port]|socket). The method throws an error if the store operation fails, for example if the current helper is invalid. It ignores the current value of the credentialStore.savePasswords and credentialStore.excludeFilters options. For example, this call stores the supplied first-factor password and prompts for the second-factor password:

The optional password argument can be either a string containing the first-factor password or a dictionary containing password, password1, password2, and password3 fields. password and password1 identify the first factor; if both are specified, password1 takes precedence. password2 and password3 identify the corresponding additional factors.

If the second argument is omitted, MySQL Shell prompts for the first-factor password. In dictionary form, a null field prompts for the corresponding factor. Omitting password2 or password3 does not prompt for that factor. Every password supplied or prompted for is stored for its corresponding authentication factor.

For example, this call stores the supplied first-factor password and prompts for the second-factor password:

shell.storeCredential('app@db.example.com:3306', {
  password1: 'first-factor-password',
  password2: null
});

shell.deleteCredential(url);

Deletes the credentials for the given URL using the current Secret Store Helper (credentialStore.helper). Throws an error if the delete operation fails, for example the current helper is invalid or there is no credential for the given URL.

shell.deleteAllCredentials();

Deletes all credentials managed by the current Secret Store Helper (credentialStore.helper). Throws an error if the delete operation fails, for example the current Helper is invalid.

var list = shell.listCredentials();

Returns a list of all URLs of credentials stored by the current Secret Store Helper (credentialStore.helper).