To maintain a preset or self-managed database on a simple application server, we recommend that you use Alibaba Cloud Data Management (DMS). This topic describes how to use DMS to connect to a database on a simple application server. In this example, a MySQL database preset in the WordPress application image is used.

Prerequisites

Background information

DMS provides an integrated solution that supports data management, schema management, user authorization, security audit, trend analysis, and data tracking. For more information about DMS, see Overview.

Step 1: View the logon information of the MySQL database

MySQL databases are preset in specific application images such as the WordPress application image that are provided by Simple Application Server. You can perform this step to view the logon information of the MySQL database preset in the WordPress application image. If the MySQL database is a self-managed database, skip this step and proceed to Step 2 to log on to the database with the password that you set for the database administrator.

  1. Log on to the Simple Application Server console.
  2. In the left-side navigation pane, click Servers.
  3. Find the WordPress server and click the server card.
  4. In the left-side navigation pane, choose Applications > Application Details.
  5. In the MySQL Information section, click Copy and then click Connect.
    MySQL Information section
  6. In the command line window of the server that appears, right-click anywhere and select Paste to paste the copied command, and then press the Enter key. View the password of the database administrator in the command output.
    Password of the MySQL database administrator
  7. Select and right-click the password of the database administrator. for subsequent logons, select Copy to copy the password and then paste it to your computer.
    Keep the password confidential.

Step 2: Configure a database user to be used to connect to DMS

  1. On the server command line, run the following command to switch to the root user:
    sudo su root
  2. Run the following command to log on to the MySQL database:
    /usr/local/mysql/bin/mysql -uroot -p
  3. At the Enter password: prompt, enter the password of the database administrator.
  4. On the MySQL command line, run the following command to create a user to be used to connect to DMS.
    In this example, a user named dms is created and the password of the user is set to Ecs123!.
    Notice You must specify the username and the password based on your needs and keep the password confidential.
    create user 'dms'@'%' IDENTIFIED BY 'Ecs123!';
  5. Run the following command to grant the user the permission to connect to the MySQL database from DMS.
    To ensure data security, we recommend that you allow access only from the DMS IP address to the MySQL database.

    In this example, the WordPress server is deployed in the China (Hangzhou) region, and Public Network is set as the data source when the MySQL database is added to DMS. In this case, you can allow access only from the DMS IP address 101.37.74.0/24 for the China (Hangzhou) region to the database. For more information, see Configure an IP address whitelist.

    grant all privileges on *.* to 'dms'@'101.37.74.0/24' with grant option;
  6. Run the following command to make the configurations take effect:
    flush privileges;
  7. Run the following command to exit MySQL:
    \q

Step 3: Use DMS to connect to the MySQL database

  1. Log on to the DMS console.
  2. In the upper-left corner, move the pointer over Add instance / Batch entry and select Create Instance.
  3. In the Create Instance dialog box, click Public Network and then click MySQL.
  4. In the Basic Information section, configure the following parameters:
    • Instance Region: Select the region where the simple application server is deployed. In this example, the China (Hangzhou) region is used.
    • Login Address: Enter the public IP address of the simple application server. In this example, the public IP address of the WordPress server is used.
    • Port: Enter 3306. Port 3306 is the default MySQL listener port.
    • Database Account: Enter a username used to connect to the database from DMS. In this example, the dms username is used.
    • Database password: Enter the password of the user used to connect to the database from DMS. In this example, Ecs123! is used.
    • Control Mode: Select Flexible Management.
    In this example, the parameters in the Advanced Information section are skipped. You can configure these parameters based on your business needs. For more information, see Register an ApsaraDB instance.
  5. Click Test Connection to test the connectivity of the database.
    The message shown in the following figure indicates that you can connect to the MySQL database on the WordPress server by using DMS. Connect to the database by using DMS
  6. Click OK. In the lower-right corner of the Create Instance dialog box, click Submit.
  7. In the Login confirmation message, click OK.
    When you are connected to the MySQL database on the WordPress server from DMS, a page similar to the following one appears. You can view and manage the database. DMS console