All Products
Search
Document Center

Simple Application Server:Use DMS to connect to a database on a simple application server

Last Updated:Apr 10, 2024

If you want to manage a preset or self-deployed 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 that is preset in the WordPress application image is used.

Prerequisites

  • A simple application server is created based on the WordPress application image. For more information, see Build a WordPress blog.

  • A rule is added to the firewall of the created WordPress server to allow traffic on MySQL listener port 3306. For more information, see Manage a firewall.

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 What is DMS?

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 that is preset in the WordPress application image. If the MySQL database is a self-deployed database, skip this step and proceed to Step 2 to log on to the database by using 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. Click the server ID in the card of the WordPress server.

  4. Click the Application Details tab.

  5. Click the Application Details tab. In the MySQL Information section, move the pointer over the command next to the Database Password parameter, click the image.png icon, and then click Remote Connection.

    image

  6. In the command line window that appears, right-click anywhere, select Paste to paste the copied command, and then press the Enter key. View the password of the database administrator in the command output.

  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.

    Important

    Keep the password confidential.

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

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

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

    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. On the MySQL command line, run the following command to create a user that can 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!.

    Important

    You must specify a username and password based on your business requirements and keep the password confidential.

    create user 'dms'@'%' IDENTIFIED BY 'Ecs123!';
  4. 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 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' identified by 'Ecs123!' with grant option;
  5. Run the following command to make the configurations immediately take effect:

    flush privileges;
  6. 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 left-side navigation pane, click Instances. On the Instance List tab, click +New.

    The first time you log on to a DMS instance, the Automatic instance access switch dialog box appears. You can turn on Automatic access settings based on your business requirements.

  3. In the Add Instance dialog box, click the Third-party Cloud/Self-managed tab and then click MySQL.

  4. In the Basic Information section, configure the following parameters based on your business requirements:

    • Database Type: MySQL is automatically filled in.

    • Network Type: Select Internet from the drop-down list.

    • Instance Region: Select the region where the simple application server is deployed. In this example, select the China (Hangzhou) region.

    • Login Address: Enter the public IP address of the simple application server. In this example, enter the public IP address of the WordPress server.

    • Port: 3306 is automatically filled in. Port 3306 is the default listener port of MySQL.

    • Database Account: Enter the username that is used to connect to the database from DMS. In this example, enter dms.

    • Database Password: Enter the password of the username that is used to connect to the database from DMS. In this example, enter Ecs123!.

    In this example, configuring parameters in the Advanced Information section is skipped. You can configure the parameters based on your business requirements. For more information, see Register a database hosted on a third-party cloud service or a self-managed database.

  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.dms连接成功

  6. Click OK. In the lower-right corner of the Add Instance dialog box, click Submit.

  7. In the Login confirmation message, click OK.

    When the MySQL database on the WordPress server is connected from DMS, you can view and manage the database.