tencent cloud

Feedback

Connecting to Cluster at Private or Public Network Address from Linux CVM Instance

Last updated: 2024-09-11 16:54:27
    TDSQL-C for MySQL supports instance-level dedicated IP address, which allows you to connect to the instance through the IP address of a read-write or read-only instance in a cluster. This document describes how to connect to an instance in a cluster from a Linux CVM instance via private or public network.

    Prerequisite

    To prepare your TDSQL-C for MySQL cluster, please refer to Creating a Cluster.
    You have created a database cluster account. For more information, see Creating Account.

    Step 1. Query the private and public IP address of the instance to be connected.

    1. Log in to the TDSQL-C for MySQL console.
    2. On the cluster list page, proceed based on the actually used view mode.
    Tab view
    List view
    1. Click Target Cluster in the cluster list on the left to enter the cluster management page.
    2. On the Cluster Details tab, find the target instance, and view its private and public network IP address under Network.
    
    1. Find the target cluster in the cluster list and click the cluster ID or Manage in the Operation column to enter the cluster management page.
    2. On the cluster management page, select the read-write or read-only instance on the instance list page, and you can view the instance private and public network IP address under Private/Public Network Address.
    

    Step 2. Connect to the target instance in a cluster

    1. Log in to a Linux CVM instance. For more information, see Quickly Configuring Linux CVM Instance.
    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:
    3.1 Run the following command to log in to the TDSQL-C for MySQL cluster.
    mysql -h hostname -P port -u username -p
    hostname: Replace it with the private network address of the target TDSQL-C for MySQL cluster as instructed in Step 1.
    port: Replace it with the private network port number.
    username: Replace it with the name of the account created in Prerequisites, which is the default account name root here for example. For example, if the private network address is 10.0.168.14:5308 and the account name is root, enter the following connection command: mysql -h 10.0.168.14 -P 5308 -u root -p.
    3.2 Enter the password corresponding to the account in the above command after Enter password: is prompted. If you forgot the password, you can reset it as instructed in Resetting Password. If MySQL [(none)]> is displayed, you have logged in to TDSQL-C for MySQL successfully.
    
    Public network connection:
    3.3 Run the following command to log in to the TDSQL-C for MySQL cluster.
    mysql -h hostname -P port -u username -p
    hostname: Replace it with the public network address of the target TDSQL-C for MySQL cluster as instructed in Step 1. If public network address is not enabled, enable it as instructed in Enabling/Disabling Public Network Address.
    port: Replace it with the public network port number.
    username: Replace it with the account name for public network connection. We recommend that you create a separate account in the console for easier connection control.
    3.4 Enter the password corresponding to the account name for public network connection after Enter password: is prompted. If you forgot the password, reset it as instructed in Resetting Password. In this example, hostname is 59281c4exxx.myqcloud.com and public network port is 15311.
    
    4. Under the MySQL [(none)]> prompt, you can send a SQL statement to the TDSQL-C for MySQL server for execution. For specific command lines, see mysql Client Commands. Below take show databases; as an example:
    

    FAQs

    How do I find the account name or reset the password to log in to the cluster?

    You can view the account name you created for cluster connection under Account Management on the cluster management page in the TDSQL-C for MySQL console. If you forgot the password, perform the Reset Password operation to change the password.
    
    

    Do I need to configure a security group for the TDSQL-C for MySQL cluster when connecting to it over the private or public network?

    Yes. For detailed directions, see Creating and Managing TencentDB Security Groups. Note that if the public network access is enabled for connection over the public network, the private network port needs to be opened in the configured security group rule.

    What should I do if I can't log in to the Linux CVM instance because the security group rules of the instance don't match properly?

    If the security group rules of the Linux CVM instance don't match properly (for example, the corresponding port is not opened), and you can't log in to the instance, you can use the Security Group (Port) Verification Tool to check the connectivity of the security group.
    
    You can identify possible causes for login failures by quick check. The port numbers to be opened may vary depending on the actual operating system of your CVM. For Linux CVM, the default port is usually 22 or 36000; for Windows CVM, it is usually 3389.
    
    Then, on the CVM instance details page, select Security Group > Modify rule and open the corresponding port. For detailed directions, see Adding Security Group Rules.

    What settings may cause a cluster connection failure?

    Check whether the CVM instance and the TDSQL-C for MySQL cluster are in the same VPC in the same region under the same Tencent Cloud account. If any of these three prerequisites is not meet, the cluster cannot be connected.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support