This topic describes how to connect to an ApsaraDB MyBase for MySQL instance by using a database client or the CLI.

Prerequisites

The operations that are described in the following topics are complete:

Use a database client to connect to an ApsaraDB MyBase for MySQL instance

You can use a general MySQL client to connect to an ApsaraDB MyBase for MySQL instance. In this topic, MySQL Workbench is used. For more information about how to download MySQL Workbench, see the MySQL Workbench download page.

  1. Start MySQL Workbench on an Elastic Compute Service (ECS) instance or your computer and choose Database > Connect to Database.
  2. Enter the information that is used to connect to the instance.
    Enter connection information in MySQL Workbench
    Parameter Description
    Hostname The endpoint that is used to connect to the instance. For more information about how to view the internal and public endpoints of the instance, see View the private and public endpoints and the port numbers of an ApsaraDB MyBase for SQL Server instance.
    • If you connect to the instance from an ECS instance and the internal network conditions are met, you must use an internal endpoint to connect to the instance. Internal network conditions:
      • The ECS instance and the ApsaraDB MyBase for MySQL instance reside in the same region.
      • The ECS instance and the ApsaraDB MyBase for MySQL instance are of the same network type. If the instances are both of the Virtual Private Cloud (VPC) type, they must reside in the same VPC.
    • If you connect to the instance from an ECS instance but the internal network conditions are not met, you must use a public endpoint to connect to the instance.
    • If you connect to the instance from your computer, you must use a public endpoint to connect to the instance.
    Port The port number that is used to connect to the instance. For more information about how to view the port number, see View the private and public endpoints and the port numbers of an ApsaraDB MyBase for SQL Server instance.
    Username The name of the account that is used to connect to the instance. For more information about how to view the account name, see Create a database account.
    Password The password of the account that is used to connect to the instance.
  3. (Optional) Click Test Connection to test the connectivity.
  4. Click OK. If the connection succeeds, a message is returned, as shown in the following figure.
    Connected

Use the CLI to connect to an ApsaraDB MyBase for MySQL instance

  1. Log on to the server from which you want to connect to an ApsaraDB MyBase for MySQL instance. For example, the server can be an ECS instance or an on-premises server.
  2. Run the following command:
    mysql -h<Endpoint> -P<Port number> -u<Username> -p<Password>      //Take note of the uppercase letter P and the lowercase letter p. 
    Parameter Description
    Endpoint The endpoint that is used to connect to the instance. For more information about how to view the internal and public endpoints of the instance, see View the private and public endpoints and the port numbers of an ApsaraDB MyBase for SQL Server instance.
    • If you connect to the instance from an ECS instance and the internal network conditions are met, you must use an internal endpoint to connect to the instance. Internal network conditions:
      • The ECS instance and the ApsaraDB MyBase for MySQL instance reside in the same region.
      • The ECS instance and the ApsaraDB MyBase for MySQL instance are of the same network type. If the instances are both of the VPC type, they must reside in the same VPC.
    • If you connect to the instance from an ECS instance but the internal network conditions are not met, you must use a public endpoint to connect to the instance.
    • If you connect to the instance from your computer, you must use a public endpoint to connect to the instance.
    Port number The port number that is used to connect to the instance. For more information about how to view the port number, see View the private and public endpoints and the port numbers of an ApsaraDB MyBase for SQL Server instance.
    Username and password The name and password of the account that is used to connect to the instance. For more information about how to view the account name and password, see Create a database account.
    If the connection succeeds, a message is returned, as shown in the following figure. Connected