Connect to a database
Updated at:
This topic describes how to connect to a PolarDB-X 1.0 database.
Procedure
-
Log on to the PolarDB-X 1.0 console.
-
In the top navigation bar, select the region where the instance is deployed.
-
Find the instance and click the instance ID to go to the Basic Information page.
- In the left-side navigation pane, click Databases.
- On the page that appears, find the target database and click its ID to open the Basic Information page.
- In the VPC Endpoint section, get the connection information from the Command Line Connection String.
- After you obtain the connection information, you can connect to the database using one of the following methods:
- If MySQL is installed on your ECS instance, you can run the following MySQL command to connect to your PolarDB-X 1.0 database.
// Connect to the database by using the MySQL command line mysql -h${DRDS_IP_ADDRESS} -P${DRDS_PORT} -u${user} -p${password} -D${DRDS_DBNAME} - PolarDB-X 1.0 supports connections from the following third-party clients. You can download the clients from their official websites.
- MySQL Workbench (Recommended)
- SQLyog
- Sequel Pro
- Navicat for MySQL
Note You can use third-party graphical user interface (GUI) clients to perform basic database operations, including data manipulation language (DML) and data definition language (DDL) operations. However, PolarDB-X 1.0 may not support the advanced features of these clients. - PolarDB-X 1.0 supports connections from third-party applications that use the following drivers, which are compliant with the official MySQL 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 MySQL is installed on your ECS instance, you can run the following MySQL command to connect to your PolarDB-X 1.0 database.
Connection examples
- The following code shows how to connect to the database using the 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();Note This example shows a connection to a MySQL 5.x database. - The following code shows a sample configuration for an application-side connection pool.
<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 using the Druid connection pool to connect to PolarDB-X 1.0. For more information about Druid, see Druid on GitHub.
Is this page helpful?