This topic describes how to configure and use the caching_sha2_password authentication plugin in MySQL-compatible mode. It covers version requirements, the authentication process, user creation, client connection configuration, and troubleshooting methods for common errors.
For more information about the features and authentication mechanism of the caching_sha2_password plugin, see Authentication.
Note
This feature is supported starting from V4.4.2 BP2.
Limitations and version requirements
When using the caching_sha2_password authentication plugin, the versions of the OBServer node, ODP, and client components must all meet the following requirements; otherwise, the connection may fail.
Component/Driver |
Version requirement |
|---|---|
| OceanBase Database (OBServer node) | From V4.4.2 BP2 (V4.4.2.2) to before V4.5.0.0, and V5.0.1 and later |
| OceanBase Database Proxy (ODP) | V4.4.0 and later |
| OBClient | V2.2.13 and later (requires libobclient V2.2.13 and later) |
| OB-JDBC | V2.4.18 and later |
| Connector/J | 8.0.9 and later |
| libmysqlclient-based client | 5.7.23 and later, or 8.0.4 and later |
| OBCI | V2.1.1.3 and later |
| ODBC Driver | V2.0.9.8 and later |
Authentication process
Before configuration, understand the authentication process of caching_sha2_password. The plugin supports two modes: fast authentication and full authentication:
- Fast authentication: The OBServer node caches authenticated user information. When a user reconnects to the same OBServer node and the password has not changed, a cache hit occurs, completing fast authentication without transmitting the password over a secure channel.
- Full authentication: The plugin performs full authentication when a user connects for the first time, after changing the password or the authentication plugin, or when the cache expires. Full authentication requires transmitting the password over a secure channel (SSL encryption or RSA public key encryption) to avoid plaintext transmission.
The authentication method varies by connection scenario:
Connection scenario |
Authentication method |
Secure channel requirement |
|---|---|---|
| The first connection after user creation or a password change | Full authentication | Either SSL or RSA required |
| Subsequent connections from the same OBServer node when the password has not been changed | Fast authentication | Not required |
| Connection via ODP | Full authentication | Either SSL or RSA required |
RSA security channel
When using RSA for full authentication, the client first requests the RSA public key from the target OBServer node, then encrypts the password with this key before transmission.
The OBServer node automatically generates an RSA key pair upon startup (controlled by the system variable sha256_password_auto_generate_rsa_keys, enabled by default). No manual generation or configuration of certificate files is required on the RSA link server side.
SSL security channel
When using SSL for full authentication, SSL configuration (certificate placement and enabling) must be completed on the OBServer node first. For details, see OBServer transmission encryption.
Step 1: Create a user that uses caching_sha2_password
Log in to the MySQL-compatible tenant as the administrator user.
obclient -h10.xxx.xxx.1 -P2881 -uroot@mysql001 -p****** -ACreate a user that uses the
caching_sha2_passwordauthentication plugin.obclient> CREATE USER user1 IDENTIFIED WITH caching_sha2_password BY '******'; Query OK, 0 rows affectedYou can also use the
ALTER USERstatement to switch an existing user to thecaching_sha2_passwordauthentication plugin:obclient> ALTER USER user1 IDENTIFIED WITH caching_sha2_password BY '******'; Query OK, 0 rows affectedNote
After creating a user or modifying the user's password or authentication plugin, the authentication cache for that user on the OBServer node immediately becomes invalid. The next connection will trigger full authentication.
Grant the user access privileges to the business database. In this example, db1 is used; grant privileges based on your actual business requirements.
obclient> GRANT ALL PRIVILEGES ON db1.* TO user1; Query OK, 0 rows affected
Optional: Set caching_sha2_password as the default authentication plugin
If not specified, new users use the mysql_native_password authentication plugin by default. If you want new users to use caching_sha2_password by default, you can set the system variable default_authentication_plugin:
obclient> SET GLOBAL default_authentication_plugin = 'caching_sha2_password';
Query OK, 0 rows affected
Notice
This setting takes effect asynchronously and may have a delay of several seconds. Users created immediately after the setting takes effect may still use the default plugin mysql_native_password. It is recommended to wait a short while before creating users and then confirm the actual effective plugin by following the method described in the "Check the user's authentication plugin" section below.
To restore the default plugin:
obclient> SET GLOBAL default_authentication_plugin = 'mysql_native_password';
Query OK, 0 rows affected
Step 2: Client connection
Command-line client
obclient and libmysqlclient-based command-line clients (such as the mysql client) that meet the version requirements do not require additional configuration parameters. During full authentication, the password is automatically transmitted encrypted using an RSA public key:
obclient -h10.xxx.xxx.1 -P2881 -uuser1@mysql001 -p****** -A
If SSL configuration has been completed on the OBServer side, the client can also establish an SSL connection using parameters such as --ssl-ca:
mysql -h10.xxx.xxx.1 -P2881 -uuser1@mysql001 -p****** --ssl-ca=/home/admin/oceanbase/wallet/ca.pem -A
Notice
obclient versions earlier than V2.2.13 do not support the caching_sha2_password authentication plugin. the connection fails with a plugin loading error. Upgrade the client version. For common errors, see the "Common errors and troubleshooting" section below.
JDBC applications
When connecting using Connector/J (version 8.0.9 or later), if the connection may trigger full authentication (first connection, connection after password modification, or connection through ODP), you need to configure one of the following parameters in the connection string or connection properties:
allowPublicKeyRetrieval=true: Allows the client to request the RSA public key from the server (default isfalse).sslMode=REQUIRED: Transmits passwords over an SSL-encrypted channel. SSL configuration must be completed on the OBServer side.
Connection example (direct connection to OBServer):
Properties props = new Properties();
props.setProperty("user", "user1@mysql001");
props.setProperty("password", "******");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://10.xxx.xxx.1:2881/db1?allowPublicKeyRetrieval=true", props);
Note
When connecting directly to OBServer, if the user's authentication cache on that node has already hit (a full authentication was successfully performed previously and the password has not changed), a connection can succeed even without configuring the above parameters. Since client connection parameters cannot detect whether the cache has hit, it is recommended to uniformly configure allowPublicKeyRetrieval=true or sslMode=REQUIRED to avoid connection failures after the password changes.
Notes on connections through ODP
When connecting to users using the caching_sha2_password authentication plugin via ODP, note the following:
- The ODP version must be V4.4.0 or later. No additional configuration is required on the ODP side for RSA links.
- Each connection through ODP is treated as a full authentication. The client must configure
allowPublicKeyRetrieval=true(for RSA links) orsslMode=REQUIRED(for SSL links). - When connecting via ODP using JDBC, the username format is
username@tenant_name#cluster_name:
Properties props = new Properties();
props.setProperty("user", "user1@mysql001#obdemo");
props.setProperty("password", "******");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://10.xxx.xxx.1:2883/db1?allowPublicKeyRetrieval=true", props);
- If the client-to-ODP connection uses SSL, refer to ODP transmission encryption for ODP-side SSL configuration.
View a user's authentication plugin
obclient> SELECT user, plugin FROM mysql.user WHERE user = 'user1';
When the value in the plugin column is caching_sha2_password, it indicates the user uses the caching_sha2_password authentication plugin.
Verify whether SSL is enabled for a connection
Execute the status (or \s) command in the MySQL client. The value in the SSL line of the output indicates whether SSL encryption is enabled for the current connection:
SSL: Cipher in use is TLS_AES_256_GCM_SHA384: SSL is enabled for the current connection.SSL: Not in use: SSL is not enabled for the current connection.
Note
OceanBase Database does not currently support viewing SSL encryption information for the current connection using the SHOW STATUS LIKE 'Ssl_cipher' statement (this statement returns an empty set). Use the client's status command to view it.
Common errors and troubleshooting
Error message |
Possible causes |
Solution |
|---|---|---|
| ERROR 1045 (42000): Plugin caching_sha2_password could not be loaded: .../caching_sha2_password.so: cannot open shared object file: No such file or directory | The client version is lower than the required version (for example, obclient earlier than V2.2.13), or the caching_sha2_password plugin is missing |
Upgrade the client to the corresponding version in the "Limitations and version requirements" section. |
| Public Key Retrieval is not allowed | Full authentication is triggered for the connection, which requires transmitting the password via RSA. However, the client has not allowed access to the server's RSA public key (the JDBC parameter allowPublicKeyRetrieval defaults to false) |
Set allowPublicKeyRetrieval=true in the JDBC connection string or connection properties, or set sslMode=REQUIRED to use an SSL connection. |
| ERROR 1045 (42000): Access denied for user 'user1'@'xxx.xxx.xxx.xxx' (using password: YES) | Incorrect password | Retry after verifying the password is correct. |