All Products
Search
Document Center

ApsaraDB for OceanBase:Connect to an OceanBase Database tenant by using a MySQL client

Last Updated:Aug 01, 2023

You can use a MySQL client to connect to a MySQL tenant of OceanBase Database. This topic describes the prerequisites and connection procedure.

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 PATH contains the directory where the MySQL client is located.

Procedure

  1. In the command line, enter the operating parameters of MySQL. in the following format:

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

    Options:

    Option

    Description

    -h

    The domain name of the OceanBase database to be connected.

    -P

    The port for connecting to the OceanBase database. By default, the port is 3306 in MySQL mode.

    -u

    The tenant account.

    -p

    The account password. For security reasons, you can skip this option. In this case, you will be prompted to enter a password later. The password is invisible.

    -A

    Specifies not to retrieve the information of all tables to ensure a quick logon when you connect to OceanBase Database.

    -c

    Specifies that comments must not be ignored in the runtime environment of MySQL.

    -D

    The name of the database to be accessed. You can change it to the corresponding business database.

  2. After the connection is created, the following default OceanBase command-line prompt appears on the command-line terminal:

    MySQL [oceanbase]> 
  3. To exit the OBClient command-line terminal, enter exit and press Enter, or press Ctrl+D.

Sample code

  1. The following sample code shows how to connect to a MySQL tenant of OceanBase Database from the MySQL client:

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

    Upon successful logon, the following results are returned:

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

    MySQL [oceanbase]> SHOW DATABASES;

    Return result:

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

    MySQL [oceanbase]> exit
  4. Execution results:

    Bye