Connect to an OceanBase tenant using a MySQL client
You can use a MySQL client to connect to a MySQL tenant in an OceanBase database. This topic describes the prerequisites, procedure, and an example.
Prerequisites
Before you connect to the database using a MySQL client, confirm the following:
Ensure that a MySQL client is installed on your local machine. The current version of OceanBase Database supports MySQL client versions 5.5, 5.6, and 5.7.
Ensure that the
PATHenvironment variable includes the directory that contains the MySQL client command.
Procedure
Enter the MySQL runtime parameters on the command line. The format is shown in the following example.
$ mysql -hxxx.xxx.xxx.xxx -P3306 -u a**** -p****** -A -c -DoceanbaseParameter descriptions:
Parameter
Description
-h
Specifies the domain name for the OceanBase database connection.
-P
Specifies the port for the OceanBase database connection. The default port for a MySQL-mode tenant is 3306.
-u
Specifies the connection account for the tenant.
-p
Specifies the account password. For security, you can omit this parameter. You are then prompted to enter the password, and the password text is not visible.
-A
Skips fetching all table information when connecting to the database. This provides the fastest logon speed.
-c
Processes comments in the MySQL runtime environment.
-D
Specifies the name of the database to access. You can change this to the name of your business database.
After you connect successfully, the default OceanBase command-line prompt appears, as shown in the following example:
MySQL [oceanbase]>To exit the OceanBase command line, enter
exitand press Enter, or use the keyboard shortcutCtrl + D.
Example
Connect to a MySQL tenant of OceanBase using a MySQL client.
$ mysql -hxxx.xxx.xxx.xxx -P3306 -u a**** -p****** -c -A -DoceanbaseAfter you log on, the following result is displayed:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 62488 Server version: 5.6.25 OceanBase 3.2.4.2 (…) (Built Feb 27 2023 17:31:19) <...Omitted...> Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [oceanbase]>View the databases.
MySQL [oceanbase]> SHOW DATABASES;The result is as follows:
+--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | test | +--------------------+ 4 rows in setTo exit, enter
exitand press Enter.MySQL [oceanbase]> exitThe output is as follows:
Bye