You can use a MySQL client to connect to a MySQL tenant of OceanBase Database. This topic describes the prerequisites and connection procedure.
Prerequisites
The MySQL client is installed locally. OceanBase Database supports MySQL clients of the following versions: V5.5, V5.6, and V5.7.
The environment variable PATH contains the directory where the MySQL client is located.
Procedure
Open a command-line terminal.
Enter the operating parameters of MySQL in the following format:
$mysql -h192.168.0.0 -uroot@obmysql#obdemo -P2883 -p**1*** -c -A oceanbaseNote
Parameters:
-h: specifies the IP address for connecting to an OceanBase database, which is usually the IP address of the ODP.
-u: specifies the tenant account in the User_name@Tenant_name#Cluster_name or Cluster_name:Tenant_name:User_name format. The default username of the administrator of a MySQL tenant is root.
-P: specifies the OceanBase Database connection port, which is also the listening port of ODP. The default value is 2883. You can customize the value as needed.
-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: specifies not to automatically retrieve the statistical information when connecting to a MySQL tenant.
oceanbase: specifies the name of the database to be accessed. You can change it to the corresponding business database.
After successful connection, the following default OceanBase command-line prompt appears on the command-line terminal:
MySQL [oceanbase]>To exit the OceanBase CLI terminal, enter
Exitand press Enter, or press Ctrl+D.
Examples
The following sample code shows how to connect to a MySQL tenant of OceanBase Database from a MySQL client:
$mysql -h192.168.0.0 -uroot@obmysql#obdemo -P2883 -p**1*** -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 62488
Server version: 5.6.25 OceanBase 2.2.20 (...) (Built Aug 10 2019 15:27:33)
<... 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
MySQL [oceanbase]> exit
Bye