This topic describes how to connect to PolarDB-X 1.0 database.
Procedure
- Log on to the PolarDB for Xscale console.
- In the top navigation bar, select the region where the target instance is located.
- Find the target instance and click the instance ID to go to the Basic Information page.
- In the left-side navigation pane, click Database Management.
- On the Databases page, find the target database and click the database ID to go to the Basic Information page.
- In the VPC Address area, find the Command Line Link Address, which contains the PolarDB-X 1.0 connection string.
- After you obtain the PolarDB-X 1.0 connection string, you can establish a connection to PolarDB-X 1.0 by using one of the following methods:
- If you have installed MySQL on your Elastic Compute Service (ECS) instance, you can run the following MySQL command to connect to the PolarDB-X 1.0 database.
// Run the MySQL connection command mysql -h${DRDS_IP_ADDRESS} -P${DRDS_PORT} -u${user} -p${password} -D${DRDS_DBNAME}
- You can connect to PolarDB-X 1.0 by using the following clients. You can go to the corresponding official websites to download the clients.
- MySQL Workbench (Recommended)
- SQLyog
- Sequel Pro
- Navicat for MySQL
Note On a third-party graphical user interface (GUI) client, you can perform basic database operations, including data addition, deletion, modification, query, and DDL operations. PolarDB-X 1.0 may not support the advanced features of the client. - You can connect to PolarDB-X 1.0 by using the following third-party program code that conforms to the official MySQL interactive protocol.
- JDBC Driver for MySQL (Connector/J)
- Python Driver for MySQL (Connector/Python)
- C++ Driver for MySQL (Connector/C++)
- C Driver for MySQL (Connector/C)
- ADO.NET Driver for MySQL (Connector/NET)
- ODBC Driver for MySQL (Connector/ODBC)
- PHP Drivers for MySQL (mysqli, ext/mysqli, PDO_MYSQL, PHP_MYSQLND)
- Perl Driver for MySQL (DBD::mysql)
- Ruby Driver for MySQL (ruby-mysql)
- If you have installed MySQL on your Elastic Compute Service (ECS) instance, you can run the following MySQL command to connect to the PolarDB-X 1.0 database.
Examples
- Sample code of JDBC Driver for MySQL (Connector/J):
//JDBC Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://drdsxxxxx.drds.aliyuncs.com:3306/doc_test","doc_test","doc_test_password"); //... conn.close();
- Connection pool configuration example
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="jdbc:mysql://drdsxxxxx.drds.aliyuncs.com:3306/doc_test" /> <property name="username" value="doc_test" /> <property name="password" value="doc_test_password" /> <property name="filters" value="stat" /> <property name="maxActive" value="100" /> <property name="initialSize" value="20" /> <property name="maxWait" value="60000" /> <property name="minIdle" value="1" /> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="poolPreparedStatements" value="true" /> <property name="maxOpenPreparedStatements" value="20" /> <property name="asyncInit" value="true" /> </bean>
Note We recommend that you use the Druid connection pool to connect to PolarDB-X 1.0. For more information about Druid, see Druid GitHub.