Step 4: Log In to the DDM Schema¶
After you create 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¶
Log in to the DDM console.
Hover on the left menu to display Service List and choose Databases > Distributed Database Middleware.
In the navigation pane, choose Instances. In the instance list, locate the required DDM instance and click its name.
In the navigation pane, choose Schemas.
In the schema list, locate the required schema and click its name.
In the Connection Address area, view CLI and JDBC connection addresses.
Note
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.
Note
For security purposes, select an ECS in the same VPC as your DDM instance.
Ensure that a MySQL client has been installed on the required ECS or the MySQL connection driver has been configured.
Before you log in to a DDM instance, configure its information on the client or connection driver.
Using the MySQL CLI to Log In to a Schema¶
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]
¶ 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
(Optional) The password authentication plug-in is used by default.
If you use the MySQL 8.0 client, this parameter is required.
-
View the command output. The following is an example output of running a MySQL command in the Windows CLI.
C:\Users\testDDM>mysql -h 192.168.0.200 -P 5066 -D db_5133 -u dbuser01 -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¶
Load the required JDBC driver.
Class.forname(com.mysql.jdbc.Driver);
Note
JDBC drivers 5.1.49 or later are recommended.
Create a database connection.
String username = "dbuser01" ; String password = "xxxxxx" ; String url = "jdbc:mysql://192.168.0.200:5066/db_5133"; Connection con = DriverManager.getConnection(url , username , password);
Create a Statement object.
Statement stmt = con.createStatement();
Execute the required SQL statement.
ResultSet rs = stmt.executeQuery("select now() as Systemtime"); con.close();
(Optional) Optimize code as needed.
loadBalanceAutoCommitStatementThreshold=5&loadBalanceHostRemovalGracePeriod=15000&loadBalanceBlacklistTimeout=60000&loadBalancePingTimeout=5000&retriesAllDown=10&connectTimeout=10000
Note
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.
loadBalanceAutoCommitStatementThreshold: defines the number of matching statements which will trigger the driver to potentially swap physical server connections.
loadBalanceHostRemovalGracePeriod: indicates the grace period to wait for a host being removed from a load-balanced connection, to be released when it is the active host.
loadBalanceBlacklistTimeout: indicates the time in milliseconds between checks of servers which are unavailable, by controlling how long a server lives in the global blacklist.
loadBalancePingTimeout: indicates the time in milliseconds that the connection will wait for a response to a ping operation when you set loadBalanceValidateConnectionOnSwapServer to true.
retriesAllDown: indicates the maximum number of connection attempts before an exception is thrown when a valid host is searched. SQLException will be returned if the threshold of retries is reached with no valid connections obtained.
connectTimeout: indicates the maximum amount of time in milliseconds that the JDBC driver is willing to wait to set up a socket connection. 0 indicates that the connection does not time out. This parameter is available to JDK-1.4 or later versions. The default value is 0.