Instance Connection

Last updated: 2019-12-06 16:39:54


    Creating an account

    1. Log in to the TDSQL Console, select the desired instance, and click the instance name or Manage in the "Operation" column to enter the instance management page.
    2. Select the Manage Account tab and click Create Account.
    3. In the pop-up dialog box, enter the account name, host, password, and remarks and click OK after confirming that everything is correct.
      The host name is actually the network egress address. If needed, you can enter % to indicate that every IP can be accessible.
    4. In the permission modification dialog box, after granting permissions as needed, click "Save Settings" to complete the permission granting. If you want to set permissions later, click "Set Later".
      The navigation bar on the left provides a graphical interface fully compatible with MySQL management. Permissions can be managed at the column level.
    5. Return to the account list. Click Modify Permission to modify the user permissions, click Clone Account to completely copy the current account permissions and create a new account, or click More to reset the password or delete the account.

    Obtaining the public network address

    1. Enter the instance details page and click Enable in the public network address bar in the basic info section.
    2. After this, the public network address and port number can be obtained. TDSQL provides a unique IP and port for access and use.

    Connection Steps

    After creating an account and obtaining its public network address, you can connect to TDSQL through third-party tools and program drivers.

    • On Windows, connection methods of command line, client, and JDBC driver are taken as examples.
    • On Linux, connection method of command line is taken as an example.

    Connecting via Windows command line

    1. Open the Windows command line and enter the following command in the correct path to MySQL.
      mysql -h public network address -P port number -u username  -p
      Enter password: **********
    2. After the relevant code is entered correctly, the following message will be displayed, indicating that the database is successfully connected to. Then, you can perform operations on the database.
      Welcome to the MySQL monitor.  Commands end with ; or \g.

    Connecting via Windows client

    1. Download a standard SQL client such as MySQL Workbench and SQLyog. SQLyog is taken as an example here.
    2. Open SQLyog, select File > New Connection, enter the corresponding host address, port, username, and password, and click Connect.
      • MySQL host address: Enter the public network address obtained earlier.
      • Username: Enter the name of the account created earlier.
      • Password: Enter the account password.
      • Port: Enter the port corresponding to the public network address.
    3. The following screen will appear after successful connection, where you can perform operations on the database.


    Connecting via Windows JDBC driver

    TDSQL supports connecting via program drivers. This document uses Java JDBC Driver for MySQL (Connector/J) as an example to describe how to connect to TDSQL.

    1. Download the .jar package of JDBC from MySQL's official website and import it into the library referenced by Java.
    2. The code to call JDBC is as follows:
           public static final String url = "public network address";
           public static final String name = "com.mysql.jdbc.Driver"; // Called JDBC successfully
           public static final String user = "username";
           public static final String password = "password";
                   Connection conn=DriverManager.getConnection("url, user, password");
    3. After successful connection, you can perform operations on the database.

      Because TDSQL needs to mark the shardkey when sharding and inserting data, these operations cannot be called with JDBC.

    Connecting via Linux command line

    This document takes CentOS 7.2 64-bit on a CVM instance as an example. For CVM instance purchase, see Purchase Method.

    1. Log in to Linux and enter the command yum install mysql to download and install a MySQL client from a Tencent Cloud image source with Yum, CentOS' built-in package manager.
    2. When complete is displayed on the command line, the MySQL client is successfully installed.
    3. Enter the command mysql -h public network address -P port -u username -p to connect to TDSQL. Then, you can perform sharding.
      show databases; is taken as an example below:

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback