Connecting to TDSQL-C Cluster

Last updated: 2021-06-25 18:41:52

    Connection Methods

    TDSQL-C (MySQL Edition) can be connected to in the following two methods:

    • Private network connection: a CVM instance can be used to connect to the private network address of a TDSQL-C database. This method relies on the high-speed private network of Tencent Cloud and features low delay.
      • The CVM instance and the database must be under the same account and in the same VPC in the same region.
      • The private network address is provided by the system by default and can be viewed in the cluster list or on the cluster details page in the TDSQL-C console.
        Note:

        CVM instances and databases in different VPCs (under the same or different accounts in the same or different regions) can be interconnected over private network through Cloud Connect Network.

    • Public network connection: you can connect to your TDSQL-C cluster at its public network address. The public network address needs to be manually enabled. It can be viewed on the cluster details page in the TDSQL-C console and can be disabled if no longer needed.
      • Enabling the public network address will expose your database services to the public network, which may lead to database intrusions or attacks. We recommend you use the private network to connect to the database.
      • Public network access to TDSQL-C is suitable for development or auxiliary database management but not for actual business access, because uncontrollable factors may cause public network access to be unavailable, such as DDoS attacks and sudden surges in access traffic.
    • DMC connection: you can access TDSQL-C through Database Management Console (DMC).

    Connection to TDSQL-C (MySQL Edition) over Private/Public Networks

    Connecting from Windows CVM instance

    1. Log in to a Windows CVM instance. For more information, please see Customizing Windows CVM Configurations.
    2. Download a standard SQL client.
      Note:

      We recommend you download MySQL Workbench. Click here and download an installer based on your operating system.

    3. Login, Sign Up, and No thanks, just start my download. will appear on the page. Select No thanks, just start my download. to download quickly.
    4. Install MySQL Workbench on this CVM instance.
      Note:

      • Microsoft .NET Framework 4.5 and Visual C++ Redistributable for Visual Studio 2015 are required for the installation.
      • You can click Download Prerequisites in the MySQL Workbench installation wizard to enter the corresponding page to download and install them. Then, install MySQL Workbench.
    5. Open MySQL Workbench, select Database > Connect to Database, enter your MySQL database instance's private (or public) network address, username, and password, and click OK to log in.
      • Hostname: enter the private (or public) network address of the target database, which can be viewed on the cluster details page in the TDSQL-C console. For public network address, check whether it has been enabled as instructed in Enabling Public Network Address.
      • Port: private (or public) network port.
      • Username: the default value is root.
      • Password: the password corresponding to the username. If you forgot the password, reset it in the TDSQL-C console.
    6. After successful login, the following page will appear, where you can view the modes and objects of the database, create tables, and perform operations such as data insertion and query.

    Connecting from Linux CVM instance

    1. Log in to a Linux CVM instance. For more information, please see Customizing Linux CVM Configurations.

    2. Taking a CVM instance on CentOS 7.2 (64-bit) as an example, run the following command to install the MySQL client:

      yum install mysql
      

      If Complete! is displayed, the MySQL client is installed successfully.

    3. Perform the corresponding operation based on the connection method:

      • Private network connection:

        1. Run the following command to log in to the TDSQL-C cluster.
          mysql -h hostname -u username -p
          
          • hostname: replace it with the private network address of the target TDSQL-C cluster, which can be viewed on the cluster details page in the TDSQL-C console.
          • username: replace it with the default username root.
        2. Enter the password corresponding to the root account of the TDSQL-C cluster after Enter password: is prompted. If you forgot the password, please reset it in the TDSQL-C console.
          If MySQL [(none)]> is displayed, you have logged in to TDSQL-C successfully.
      • Public network connection:

        1. Run the following command to log in to the TDSQL-C cluster.
          mysql -h hostname -P port -u username -p
          
          • hostname: replace it with the public network address of the target TDSQL-C cluster, which can be viewed together with the port on the cluster details page in the TDSQL-C console. If the public network address has not been enabled, please enable it as instructed in Enabling Public Network Address.
          • port: replace it with the public network port number.
          • username: replace it with the public network connection username. We recommend you create a separate account in the console for easier connection control.
        2. Enter the password corresponding to the public network connection username after Enter password: is prompted. If you forgot the password, reset it in the TDSQL-C console.
          In this example, hostname is 59281c4exxx.myqcloud.com and public network port is 15311.
    4. Under the MySQL \[(none)]> prompt, you can send an SQL statement to the TDSQL-C server for execution. For specific commands, please see mysql Client Commands.
      Below takes show databases; as an example:

    Connection Through DMC

    1. Log in to the TDSQL-C console and click Login in the Operation column in the cluster list.
    2. On the login page of DMC, enter "root" as the account and the password configured for the root account during cluster creation and click Log In.
      Note:

      DMC enables you to easily access instances, manipulate tables and databases, manage instance sessions, and monitor InnoDB lock waits, SQL window, etc. in real time.

    Appendix 1. Enabling Public Network Address

    Note:

    To connect over the public network, you need to enable the public network address of your database first.

    1. Log in to the TDSQL-C console and click a cluster name in the cluster list to enter the cluster details page.
    2. On the cluster details page, click Enable after Public network address for cluster connection.
    3. In the pop-up window, click OK.
      Note:

      • Once enabled successfully, the public network address can be viewed in the connection information.
      • The public network access can be disabled by using the switch. When it is enabled again, the public IP corresponding to the domain name remains the same.