Connecting to MySQL Instance

Last updated: 2020-08-10 11:55:02

    TencentDB for MySQL 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 TencentDB instance. This method relies on the high-speed private network of Tencent Cloud and features low delay.

      • The two instances must be under the same account and in the same VPC in the same region, or both in the classic network.
      • The private network address is provided by the system by default and can be viewed in the instance list or on the instance details page in the TencentDB for MySQL Console.
    • Public network connection: if you cannot access the private network, you can connect to your TencentDB for MySQL instance at its public network address. The public network address needs to be manually enabled. It can be viewed on the instance details page in the TencentDB for MySQL Console and can be disabled if no longer needed.

      • The public network address can be enabled only for instances in the Guangzhou, Shanghai, Beijing, Chengdu, Chongqing, Hong Kong (China), Singapore, Seoul, Tokyo, and Silicon Valley regions.
      • 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 connection to TencentDB is suitable for development or auxiliary database management but not for actual business connection, because uncontrollable factors may cause public network connection to be unavailable, such as DDoS attacks and sudden surges in access traffic.

    The following describes how to log in to a TencentDB for MySQL instance from Windows and Linux CVM instance over the private and public networks.

    Accessing from Windows CVM Instance

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

      Note:

      We recommend you download MySQL Workbench. Visit https://dev.mysql.com/downloads/workbench/ and download an appropriate installer based on your system.

    3. Login, Sign Up, and No, thanks, just start my download. will appear on the page. Select No, thanks, just start my download. for quick download.
    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 TencentDB for MySQL instance's private (or public) network address, username, and password, and click OK to log in.
      • Hostname: enter the private (or public) network address, which can be viewed with the port on the instance details page in the TencentDB for MySQL 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 username is root by default. For public network connection, we recommend you create a separate account for easier connection control.
      • Password: the password corresponding to Username. If you forgot the password, reset it as instructed in Resetting Password.
    6. After successful login, the following page will appear, where you can view the modes and objects of the MySQL database, create tables, and perform operations such as data insertion and query.

    Accessing from Linux CVM Instance

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

    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 TencentDB for MySQL instance:
          mysql -h hostname -u username -p
          • hostname: replace it with the private network address of the target TencentDB for MySQL instance, which can be viewed on the instance details page in the TencentDB for MySQL Console.
          • username: replace it with the default username root.
        2. Enter the password corresponding to the root account of the TencentDB for MySQL instance after Enter password: is prompted. If you forgot the password, please reset it as instructed in Resetting Password.
          If MySQL [(none)]> is displayed, you have logged in to MySQL successfully.
      • Public network connection:

        1. Run the following command to log in to the TencentDB for MySQL instance:
          mysql -h hostname -P port -u username -p
          • hostname: replace it with the public network address of the target TencentDB for MySQL instance, which can be viewed together with the port on the instance details page in the TencentDB for MySQL 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 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 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 an SQL statement to the MySQL server for execution. For specific command lines, please see mysql Client Commands.
      Below takes show databases; as an example:

    Appendix 1. Enabling Public Network Connection Address

    1. Log in to the TencentDB for MySQL Console. In the instance list, click an instance name or Manage in the "Operation" column to enter the instance details page.
    2. Find Public Network Address in the basic information section on the instance details page and click Enable.
    3. Click OK to start enabling public network access.
    4. Once enabled successfully, the public network address can be found in the basic information section.

      Note:

      The public network connection can be disabled using the switch. When it is enabled again, the public network address corresponding to the domain name remains the same.

    Appendix 2. Network Connectivity Verification Method

    We recommend you troubleshoot and locate network connectivity problems quickly with the telnet command. For more information, please see telnet Command.

    If the verification with telnet found that the network access of the TencentDB instance was good, but an error was reported when you tried to log in to it on the command line in the CVM instance, please see Connection.

    Appendix 3. Troubleshooting Connection Errors

    If you encounter connection errors, we recommend you use One-Click Connectivity Checker to troubleshoot the problem first and then find the corresponding solution in [Troubleshooting Connection Errors] according to the check report.

    Was this page helpful?

    Was this page helpful?

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