You can use a MySQL client to connect to a MySQL tenant of OceanBase Database. This topic describes the methods and procedure of connecting to OceanBase Database by using a MySQL client.
Prerequisites
Before you connect to an OceanBase database by using a MySQL client, make sure that the following conditions are met:
A MySQL client is installed on your server. OceanBase Database supports MySQL clients of the following versions: 5.5, 5.6, and 5.7.
The environment variable
PATHcontains the directory where the MySQL client is located.Note
When you connect to OceanBase Database by using a MySQL 8.0 client, you must specify the following string in the connection command: --default_auth=mysql_native_pasowrd.
This is because the default encryption algorithm is mysql_native_password for MySQL 5.6 and MySQL 5.7 and caching_sha2_password for MySQL 8.0.
Procedure
Open a command line.
Connect to OceanBase Database by using MySQL commands.
To connect to the MySQL tenant by using an OBProxy, run the following command:
$mysql -h10.10.10.1 -u****@obmysql#obdemo -P2883 -ppassword -c -A oceanbaseor
$mysql -h10.10.10.1 -uobdemo:obmysql:**** -P2883 -ppassword -c -A oceanbaseNote
-h: specifies the IP address for connecting to OceanBase Database, which is usually the IP address of an OBProxy.
-u: specifies the tenant account. Two account formats are supported:
Username@Tenant name#Cluster nameandCluster name:Tenant name:Username. The default username of the tenant administrator isroot.-P: specifies the port for connecting to OceanBase Database, which is also the listening port of the OBProxy. Default value: 2883, which can be customized.
-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 not to ignore comments in the runtime environment.
-A: specifies not to automatically retrieve the statistical information when connecting to the tenant.
oceanbase: the name of the database to be accessed. You can change it to a business database.
To directly connect to the MySQL tenant, run the following command:
$mysql -h10.10.10.1 -uusername@obmysql -P2881 -ppassword -c -A oceanbaseNote
-h: specifies the IP address for connecting to an OceanBase database, which is usually the IP address of an OBServer.
-u: specifies the tenant account in the
Username@Tenant nameformat. The default username of the tenant administrator isroot.-P: specifies the port for connecting to OceanBase Database. Default value: 2881, which can be customized.
-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 not to ignore comments in the runtime environment.
-A: specifies not to automatically retrieve the statistical information when connecting to the 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 by using this OBServer.
After the connection is established, the following command-line prompt is displayed by default:
MySQL [oceanbase]>To exit the MySQL command line, enter
exitand press Enter, or press the shortcut key Ctrl + D.
Example
Connect to OceanBase Database by using a MySQL client
$mysql -h10.10.10.1 -u****@obmysql#obdemo -P2883 -p****** -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 5751
Server version: 5.6.25 OceanBase 4.0.0 (r10100032022041510-a09d3134c10665f03fd56d7f8bdd413b2b771977) (Built Apr 15 2022 02:16:22)
<...>
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
More information
If errors occur when you connect to an OceanBase database from a MySQL client, we recommend that you refer to the official MySQL documentation.