Connect to an OceanBase tenant using a MySQL client

更新时间: 2026-01-18 19:59:03

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 PATH environment variable includes the directory that contains the MySQL client command.

Procedure

  1. 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 -Doceanbase

    Parameter 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.

  2. After you connect successfully, the default OceanBase command-line prompt appears, as shown in the following example:

    MySQL [oceanbase]> 
  3. To exit the OceanBase command line, enter exit and press Enter, or use the keyboard shortcut Ctrl + D.

Example

  1. Connect to a MySQL tenant of OceanBase using a MySQL client.

    $ mysql -hxxx.xxx.xxx.xxx -P3306 -u a**** -p****** -c -A -Doceanbase

    After 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]>
  2. View the databases.

    MySQL [oceanbase]> SHOW DATABASES;

    The result is as follows:

    +--------------------+
    | Database           |
    +--------------------+
    | oceanbase          |
    | information_schema |
    | mysql              |
    | test               |
    +--------------------+
    4 rows in set
  3. To exit, enter exit and press Enter.

    MySQL [oceanbase]> exit
  4. The output is as follows:

    Bye
上一篇: Use a client 下一篇: Connect to an OceanBase Database tenant by using OBClient