Help Center> Distributed Database Middleware> Getting Started> Step 4: Log In to the DDM Schema
Updated on 2023-10-09 GMT+08:00

Step 4: Log In to the DDM Schema

After you buy a DDM instance, you can log in to it using a client such as Navicat, or connect to the required schema in the instance using the CLI or JDBC driver.

This section describes how to log in to a DDM instance or a schema.

Preparations

Before you log in to your DDM instance or schema, you have to obtain its connection address.

Obtaining the Schema Connection Address

  1. Log in to the DDM console.
  2. In the instance list, locate the required DDM instance and click its name.
  3. In the navigation pane, choose Schemas.
  4. In the schema list, locate the required schema and click its name.
  5. In the Connection Address area, view CLI and JDBC connection addresses.

    Figure 1 Schema connection address
    • If load balancing is enabled, one floating IP address will be assigned to a DDM instance even if it has multiple nodes. You can use this address to connect to the DDM instance for load balancing.
    • There are some historical instances that do not support load balancing, so they have multiple IP addresses. For load balancing, you can use JDBC connection strings to connect to them.
    • If read-only groups are created, each group will be assigned a load balancing address for service isolation.

Connection Methods

For details about method 1, see Using Navicat to Log In to a DDM Instance.

For details about method 2, see Using the MySQL CLI to Log In to a Schema.

For details about method 3, see Using a JDBC Driver to Log In to a Schema.

For details about method 4, see Logging In to a DDM Instance on the DDM Console.

  1. For security purposes, select an ECS in the same VPC as your DDM instance.
  2. Ensure that a MySQL client has been installed on the required ECS or the MySQL connection driver has been configured.
  3. Before you log in to a DDM instance, configure its information on the client or connection driver.

Using Navicat to Log In to a DDM Instance

  1. Log in to the DDM console, locate the required DDM instance, and click its name.
  2. Ask technical support to add an EIP to the feature whitelist. In the Instance Information area, click Bind. In the displayed dialog box, select the EIP and click OK. Bind the EIP with your DDM instance.
  3. In the navigation pane on the left, click the VPC icon and choose Access Control > Security Groups.
  4. On the Security Groups page, locate the required security group and click Manage Rule in the Operation column. On the displayed page, click Add Rule. Configure the security group rule as needed and click OK.

    After binding an EIP to your DDM instance, set strict inbound and outbound rules for the security group to enhance database security.

  5. Open Navicat and click Connection. In the displayed dialog box, enter the host IP address (EIP), username, and password (DDM account).

    Navicat12 is recommended for Navicat clients.

  6. Click Test Connection. If a message is returned indicating that the connection is successful, click OK. The connection will succeed 1 to 2 minutes later. If the connection fails, the failure cause is displayed. Modify the required information and try again.

Using Navicat to access a DDM instance is similar to using other visualized MySQL tools such as MySQL Workbench. Therefore, the procedure of using other visualized MySQL tools to connect to a DDM instance has been omitted.

Using the MySQL CLI to Log In to a Schema

  1. Log in to the required ECS, open the CLI, and run the following command:

    mysql -h ${DDM_SERVER_ADDRESS} -P${DDM_SERVER_PORT} -u${DDM_USER} -p [-D${DDM_DBNAME}] [--default-character-set=utf8][--default_auth=mysql_native_password] [--ssl]
    Table 1 Parameter description

    Example Parameter

    Description

    Example Value

    DDM_SERVER_ADDRESS

    IP address of the DDM instance

    192.168.0.200

    DDM_SERVER_PORT

    Connection port of the DDM instance

    5066

    DDM_USER

    Account of the DDM instance

    dbuser01

    DDM_DBNAME

    (Optional) Name of the target schema in the DDM instance

    -

    default-character-set=utf8

    (Optional) Select character set UTF-8 for encoding.

    Configure this parameter if garbled characters are displayed during parsing due to inconsistency between MySQL connection code and actually used code.

    -

    default_auth=mysql_native_password

    The password authentication plug-in is used by default.

    -

    ssl

    (Optional) To use SSL to encrypt connections, you need to enable SSL first.

    -

    • If you use the MySQL 8.0 client, set default_auth to mysql_native_password.
    • If you have enabled SSL, encrypted connections are used by default.

  2. View the command output. The following is an example output of running a MySQL command in the Windows CLI.

    C:\Users\testDDM>mysql -h192.168.0.200 -P5066 -Ddb_5133 -udbuser01 -p
    Enter password:
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
     
    Welcome to the MySQL monitor.  Commands end with ;or \g.
    Your MySQL connection id is 5
    Server version: 5.6.29
     
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
     
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
     
    mysql>

Using a JDBC Driver to Log In to a Schema

To perform the following operations, install the JDBC driver of 5.1.49 or later versions. JDBC driver download address: https://dev.mysql.com/doc/index-connectors.html.

  1. Load the required JDBC driver.

    Class.forname(com.mysql.jdbc.Driver);

  2. Create a database connection.

    String username = "dbuser01" ;
    String password = "xxxxxx" ; 
    String url = "jdbc:mysql://ip:port/db_name";
    Connection con = DriverManager.getConnection(url , username , password);

    For details, see the example parameter value in Table 2.

    Table 2 URL parameter description

    Parameter

    Description

    Example Value

    ip:port

    Indicates the connection address and port number for connecting to your DDM instance.

    192.168.0.200:5066

    See Obtaining the Schema Connection Address to obtain the JDBC connection address and port number.

    db_name

    Indicates the name of a schema.

    db_5505

    On the DDM console, locate the required instance and click its name. In the navigation pane on the left, choose Schemas to view the schema name.

  3. Create a Statement object.

    Statement stmt = con.createStatement();

  4. Execute the required SQL statement.

    ResultSet rs = stmt.executeQuery("select now() as Systemtime");
    con.close();

  5. (Optional) Optimize code as needed.

    loadBalanceAutoCommitStatementThreshold=5&loadBalanceHostRemovalGracePeriod=15000&loadBalanceBlacklistTimeout=60000&loadBalancePingTimeout=5000&retriesAllDown=10&connectTimeout=10000&useSSL=true";
    • Parameters loadBalanceAutoCommitStatementThreshold and retriesAllDown must be configured based on the example in 5. Otherwise, an infinite loop may occur during the connection switchover, resulting in stack overflow.
    • For details about parameter configurations, see Table 3.
    Table 3 Parameter description

    Parameter

    Description

    Example Value

    loadBalanceAutoCommitStatementThreshold

    Indicates the number of statements executed before a reconnection.

    • If the parameter value is set to 5, a reconnection is required after five SQL statements (queries or updates) are executed.
    • If it is set to 0, a sticky connection is initiated instead of a reconnection.

    When automatic submission is disabled (autocommit is set to false), the system waits for the transaction to complete and then determines whether to initiate a reconnection.

    5

    loadBalanceHostRemovalGracePeriod

    Indicates the grace period to wait for a host being removed from a load balancing connection, and to be released when it is the active host.

    15000

    loadBalanceBlacklistTimeout

    Indicates the time in milliseconds between checks of servers which are unavailable, by controlling how long a server lives in the global blacklist.

    60000

    loadBalancePingTimeout

    Indicates the time in milliseconds for waiting for the ping response of each load balancing connection.

    5000

    retriesAllDown

    Indicates the maximum number of polling retries when all connection addresses fail.

    SQLException will be returned if the threshold of retries is reached with no valid connections obtained.

    10

    connectTimeout

    Specifies the timeout interval for establishing a socket connection with a database server.

    Unit: millisecond. A value of 0 indicates that connection establishment never times out. This parameter setting is used for JDK 1.4 or later versions.

    10000

    socketTimeout

    Specifies the timeout interval for a socket operation (read and write).

    Unit: millisecond. A value of 0 indicates that a socket operation never times out.

    Set this parameter based on your service requirements.

    useSSL

    Indicates that an SSL connection is used to connect to DDM.

    true

Logging In to a DDM Instance on the DDM Console

  1. Log in to the DDM console.
  2. In the navigation pane, choose Instances.
  3. In the instance list, locate the required instance and click Log In in the Operation column.

    On the displayed page, enter the required username and password.
    Figure 2 Login page

  4. On the displayed page, enter username and password of the DDM account.
  5. Click Test Connection.
  6. (Optional) Enable Collect Metadata Periodically and Show Executed SQL Statements.
  7. Ensure that all settings are correct and click Log In.