Access MySQL Database

Last updated: 2019-12-27 14:25:47

PDF

Access Methods

TencentDB for MySQL can be accessed in three methods:

  • Private network access: A CVM instance can be used to access the private network address that is automatically assigned to a TencentDB instance. This access method relies on the high-speed private network of Tencent Cloud and features low delay. Both instances should reside in the same region, be under the same account, and use the same type of networks (both in the basic network or in the same VPC).
  • Public network access: TencentDB for MySQL can be accessed using a public network address.
  • For public network access, the database instance's public IP needs to be enabled, which may expose your database service to attacks or intrusions on the public network. Therefore, it is recommended to log in to the database over the private network.
  • Public network access to TencentDB is suitable for development or auxiliary management of databases but not for formal business access, as potentially uncontrollable factors may lead to unavailability of the public network access, such as DDoS attacks and bursts of high-traffic access.
  • Peering connection: For more information on private network access between CVM and TencentDB instances which reside in different regions, are under different accounts, or use different types of networks. For more information on billing, see Billing Overview of Peering Connection.

Access to a TencentDB for MySQL Instance

Enabling the Public Network Access Address (Optional)

To use the public network access, you need to enable the public network address of your TencentDB instance.

  1. Log in to the TencentDB for MySQL Console.
  2. In the instance list, select the instance to be modified and click the instance name or Manage in the "Operation" column to enter the instance details page.
  3. Find Public Network Address in the basic information section on the instance details page and click Enable.
  4. Click OK and the enabling process starts.
  5. After the public network address is enabled successfully, it can be found in the basic information.
  6. The public network access can be disabled using the switch. When it is enabled again, the public IP corresponding to the domain name remains the same.

Login on Windows

  1. Log in to a Windows-based CVM instance that resides in the same region as the TencentDB for MySQL instance and is accessible.
    For more information on how to log in to a CVM instance, see Getting Started with Windows-based CVM or Getting Started with Linux-based CVM. Network accessibility means that both the CVM instance and the TencentDB instance are in the basic network or in the same VPC.
  2. Download a standard SQL client. MySQL Workbench is recommended for Windows. Visit https://dev.mysql.com/downloads/workbench/ on the CVM instance and download the appropriate installer based on your system version.
  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. Microsoft .NET Framework v4.5 and Visual C ++ Redistributable for Visual Studio 2015 are required for the installation. If needed, you can click "Download Prerequisites" in the MySQL Workbench installation wizard to install them.
  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 on the instance details page in the TencentDB for MySQL Console.
    • Port: Private (or public) network port.
    • Username: The username is "root" by default. For public network access, you are recommended to create a separate account for easier access control.
    • Password: Password of the username.
  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.

Login on Linux

  1. Log in to a Linux-based CVM instance that resides in the same region as the TencentDB for MySQL instance and is accessible.
    For more information on how to log in to a CVM instance, see Getting Started with Windows-based CVM or Getting Started with Linux-based CVM. Network accessibility means that both the CVM instance and the TencentDB instance are in the basic network or in the same VPC.
    In the following example, the CVM instance runs on CentOS 7.2_64. You can use Yum, the package manager built in CentOS, to download and install the MySQL client from the Tencent Cloud image source.
    Install the MySQL client by running the following command:
    yum install mysql
    If "Complete!" is displayed, it means the MySQL client is installed successfully.
  2. Perform the following operations based on the selected access method:
    • For private network access, run the following command to log in to the TencentDB for MySQL instance.
      mysql -h hostname -u username -p
      • Replace "hostname" with the private (or public) network address of the target instance, replace "username" with the default username "root", and enter its password when prompted with "Enter password:".
      • If "MySQL [(none)]" is displayed, it means that you have logged in to MySQL successfully.
    • For public network access, run the following command to log in to the TencentDB for MySQL instance.
      mysql -h hostname -P port -u username -p
      • Replace "hostname" with the public IP address of the target instance, replace "port" with the public network port, replace "username" with the username for public network access such as "cdb_outerroot", and enter its password when prompted with "Enter password:".
  • The username is for public network access. You are recommended to create a separate account for easier access control.
    • In this example, hostname is 59281c4exxx.myqcloud.com and public network port is 15311.
  1. Under the prompt "MySQL [(none)]>", you can send an SQL statement to the MySQL server for execution. For specific command lines, see here.
    Take show databases; for example as below: