You can use a MySQL client to connect to a MySQL tenant of OceanBase.
Procedure
Open a command-line terminal and make sure that the environment variable
PATHcontains the directory where the MySQL client command is located.Specify the operating parameters to execute MySQL queries in the following formats:
Connection through an OBProxy:
$mysql -h10.10.10.1 -u******@obmysql#obdemo -P2883 -p**1*** -c -A oceanbaseNote
-h: Specifies the IP address for connecting to OceanBase Database, which is usually the IP address of the OBProxy.
-u: The tenant account. Two account formats are supported:
Username@Tenant name#Cluster nameandCluster name:Tenant name:UsernameThe default username of the administrator of the MySQL tenant is root.-P: Specifies the OceanBase Database connection port, which is also the listening port of OBProxy. The default value is 2883. You can customize the value as required.
-c: Specifies that comments must not be ignored in the runtime environment of MySQL.
-A: Indicates that the statistical information is not automatically retrieved when connecting to a MySQL tenant.
oceanbase: The name of the database to be accessed. You can change it to a business database.
Direct connection:
$mysql -h10.10.10.1 -u******@obmysql -P2881 -p**1*** -c -A oceanbaseNote
-h: The IP address for connecting to OceanBase, which is usually the IP address of an OBServer.
-u: The tenant account. Two account formats are supported:
Username@Tenant nameandTenant name:UsernameThe default username of the administrator of the MySQL tenant is root.-P: Specifies the OceanBase Database connection port. The default value is 2881. You can customize the value as required.
-p: Specifies the account password. For security reasons, you do not need to specify this parameter. In that case, you will be prompted to enter a password later. The password is invisible.
-c: Specifies that comments must not be ignored in the runtime environment of MySQL.
-A: Indicates that the statistical information is not automatically retrieved when connecting to a MySQL tenant.
oceanbase: The name of the database to be accessed. You can change it to a business database.
When you use the direct connection method, make sure that the tenant resources are distributed on the OBServer you specified. Otherwise, you cannot connect to the tenant through this OBServer.
After the connection is established, the following command-line prompt is displayed by default:
MySQL [oceanbase]>If you want to exit the OceanBase command-line terminal, enter
exitand press Enter, or press the shortcut key Ctrl + D .
Example
Connect to a MySQL tenant of OceanBase Database from a MySQL client:
$mysql -h10.10.10.1 -u******@obmysql#obdemo -P2883 -p**1*** -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 3221495183
Server version: 5.7.25 OceanBase 2.2.77 (...) (Built Oct 23 2020 11:00:48)
<...Omitted...>
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [oceanbase]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
MySQL [oceanbase]> exit
Bye