Connect to a database on a server using DMS

Updated at:

You can use Alibaba Cloud Data Management (DMS) to maintain databases on your Simple Application Server. This method applies to both pre-installed and self-managed databases. This topic uses the pre-installed MySQL database in a WordPress application image as an example to demonstrate how to connect to a database on a server using DMS.

Prerequisites

Background information

DMS is a service that provides features such as data management, structure management, user authorization, security audits, data trend analysis, and data tracking. For more information about DMS features, see What is Data Management (DMS)?.

Step 1: View MySQL logon information

Some application images provided by Simple Application Server, such as WordPress, include a pre-installed MySQL database. Follow the steps in this section to view the MySQL logon information. If you installed the database yourself, you can skip this section and use the database administrator password that you set during installation.

  1. Log on to the Simple Application Server console.

  2. In the left-side navigation pane, click Servers.

  3. On the card for the WordPress server, click the instance ID.

  4. Click the Application Details tab.

  5. On the Application Details tab, in the MySQL Information section, find the command to query the MySQL password. Hover over the command, click the image.png icon, and then click Remote Connection.

  6. In the command line of the remote server, right-click to paste the command and press Enter. The password for the database administrator is displayed.

  7. Select the database administrator password. Then, right-click and select Copy. Paste the password to your local host for later use.

    Important

    Keep the password in a safe place.

Step 2: Set up a database user for the DMS connection

  1. Run the following command to log on to the MySQL database.

    mysql -uroot -p
  2. At the Enter password: prompt, enter the database administrator password.

    Note

    For data security purposes, no output is returned when you enter a password. You need only to enter the correct password and then press the Enter key.

  3. In the command line of the MySQL application, run the following command to create a user for the DMS connection.

    This example creates a user named dms and sets the password to Ecs123!.

    Important

    Set a custom password and keep it in a safe place.

    create user 'dms'@'%' IDENTIFIED BY 'Ecs123!';
  4. Run the following command to grant the user remote connection permissions for DMS.

    For data security, grant remote connection permissions only to DMS IP addresses.

    In this example, the WordPress server is in the China (Hangzhou) region and connects to the DMS data source over the public network. Therefore, you must grant permissions only to the DMS IP address range 101.37.74.0/24. For more information, see DMS IP address ranges.

    grant all privileges on *.* to 'dms'@'101.37.74.0/24' identified by 'Ecs123!' with grant option;
  5. Run the following command to apply the configuration immediately.

    flush privileges;
  6. Run the following command to exit the MySQL application.

    \q

Step 3: Connect to the MySQL database using DMS

  1. Log in to DMS 5.0.

  2. In the Database Instances area on the left side of the console home page, click the Add Instanceadd icon.

    Note

    Alternatively, on the top menu bar, choose Data Assets > Instances and then click Add.

  3. In the Add Instance dialog box, configure the following key parameters.

    This section describes only the key parameters. You can keep the default values for other parameters. For more information about all parameters, see Add a self-managed database or a database from another cloud.

    Category

    Configuration Item

    Description

    Data Source

    -

    Select Third-party Cloud/Self-managed.

    Basic Information

    Database Type

    The default is MySQL.

    Instance Source

    Select Public Network.

    Instance Region

    Select the region where the Simple Application Server is located. In this example, select China (Hangzhou).

    Logon Address

    Enter the public IP address of the Simple Application Server. In this example, enter the public IP address of the WordPress server.

    Port

    The default MySQL listener port is 3306.

    Database Account

    The username of the database account used to connect to DMS. In this example, enter dms.

    Database Password

    The password for the database user that connects to DMS. In this example, enter Ecs123!.

  4. Click Test Connection.

    If a success message appears as shown in the following figure, it indicates that DMS can connect to the MySQL database on the WordPress server.dms连接成功

  5. Click Confirm, and then in the lower-right corner of the Add Instance dialog box, click Submit.