You can use the MySQL client to connect to a user tenant of OceanBase AI Database. This topic describes the prerequisites and procedure, and provides an example to help you get started.
Prerequisites
Before you connect to OceanBase AI Database by using the MySQL client, make sure that the following conditions are met:
The MySQL client is installed on your local server. OceanBase AI Database supports MySQL client versions 5.5, 5.6, and 5.7.
The environment variable
PATHcontains the directory where the MySQL client is located.The client is in the allowlist of the tenant. For more information about how to query and configure a tenant allowlist, see View and set tenant allowlists.
Procedure
Connect through ODP
Run the following MySQL command to connect to OceanBase AI Database by using OceanBase Database Proxy (ODP):
mysql -h$host -P$port -u$user_name -p****** [-c] [-A] [$database_name]
Parameter description:
-hspecifies the IP address for connecting to OceanBase AI Database. Replace$hostwith the actual IP address of ODP used for connection.-Pspecifies the port for connecting to OceanBase AI Database. Replace$portwith the port customized when ODP is deployed. The default value is2883.-uspecifies the tenant account for connecting to OceanBase AI Database.$user_namecan be in any of the following formats:username@tenant_name#cluster_name,cluster_name:tenant_name:username,cluster_name-tenant_name-username, andcluster_name.tenant_name.username. You can use the MySQL client only to connect to a user tenant. The default username of the administrator of a user tenant isroot.Note
- When connecting to OceanBase AI Database through ODP, you can obtain the cluster name as follows:
First, connect directly to OceanBase AI Database. Then, use theSHOW PARAMETERS LIKE 'cluster';command to get the cluster name. The value ofVALUEin the returned result corresponds to the name of the OceanBase AI Database cluster. - If ODP proxies multiple clusters, you must specify the cluster name when connecting. If ODP proxies only one cluster, specifying the cluster name is not required.
- When connecting to OceanBase AI Database through ODP, you can obtain the cluster name as follows:
-pspecifies the account password for connecting to OceanBase AI Database. Replace******with the actual password.Note
For security purposes, we recommend that you do not directly enter the password on the CLI, especially in an environment where the script or historical records are visible. You can skip this option and enter the password when being prompted to.
-cis optional, which specifies that comments are not ignored in the runtime environment of MySQL.Note
Hints are special comments that are not affected by the
-coption.-Ais optional, which specifies not to automatically retrieve the statistical information when the client connects to OceanBase AI Database.$database_nameis optional, which specifies the default database to be used after the connection to OceanBase AI Database is established. By default, no database is accessed after the connection is established if you do not specify this option. You need to manually select a database.
Example:
mysql -h10.10.10.1 -uuser001@obmysql#obdemo -P2883 -p****** -c -A oceanbase
Connect via direct connection
Run the following MySQL command to directly connect to OceanBase AI Database:
mysql -h$host -P$port -u$user_name -p****** [-c] [-A] [$database_name]
Parameter description:
-hspecifies the IP address for connecting to OceanBase AI Database. Replace$hostwith the actual IP address of the OBServer node for direct connection.Notice
When you use the direct connection method, make sure that the tenant resources are distributed on the OBServer node you specified. Otherwise, you cannot connect to the tenant by using this OBServer node.
-Pspecifies the port for connecting to OceanBase AI Database. Replace$portwith the port customized when OceanBase AI Database is deployed. The default value is2881.-uspecifies the tenant account for connecting to OceanBase AI Database. The format of$user_nameisusername@tenant_name. The default username of the administrator of a user tenant isroot.Notice
When you directly connect to OceanBase AI Database, specify the username and tenant name in the format of
username@tenant_namefor the-uoption, and do not specify the cluster name. If you include the cluster name in-u, a connection error is returned.-pspecifies the account password for connecting to OceanBase AI Database. Replace******with the actual password.Note
For security purposes, we recommend that you do not directly enter the password on the CLI, especially in an environment where the script or historical records are visible. You can skip this option and enter the password when being prompted to.
-cis optional, which specifies that comments are not ignored in the runtime environment of MySQL.Note
Hints are special comments that are not affected by the
-coption.-Ais optional, which specifies not to automatically retrieve the statistical information when the client connects to OceanBase AI Database.$database_nameis optional, which specifies the default database to be used after the connection to OceanBase AI Database is established. By default, no database is accessed after the connection is established if you do not specify this option. You need to manually select a database.
Example:
mysql -h10.10.10.1 -uuser001@obmysql -P2881 -p****** -c -A oceanbase
Connection example
Open a command-line terminal.
Run the following command to connect to a user tenant of OceanBase AI Database by using the MySQL client:
mysql -hxxx.xx.xxx.xxx -P2883 -uroot@mysql001#test432 -p****** -A oceanbaseThe return result is as follows:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 5.6.25 OceanBase 4.3.2.0 (r200000272024061717-93c0ed73ebbcac6edbf7b585860b75d825935358) (Built Jun 17 2024 18:06:04) <...> Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [oceanbase]>To exit the MySQL client, enter
exitand press Enter, or press the keyboard shortcut Ctrl + D.
More information
If errors occur when you connect to OceanBase AI Database by using the MySQL client, we recommend that you refer to the official MySQL documentation for troubleshooting.