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.
Log on to the Simple Application Server console.
In the left-side navigation pane, click Servers.
Click the server ID in the card of the WordPress server.
Click the Application Details tab.
Click the Application Details tab. In the MySQL Information section, move the pointer over the command next to the Database Password parameter, click the icon, and then click Remote Connection.
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.
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.
ImportantKeep the password confidential.
Step 2: Configure a database user to be used to connect to DMS
Run the following command to log on to the MySQL database:
mysql -uroot -p
At the Enter password: prompt, enter the password of the database administrator.
NoteFor 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.
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 toEcs123!
.ImportantYou must specify a username and password based on your business requirements and keep the password confidential.
create user 'dms'@'%' IDENTIFIED BY 'Ecs123!';
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;
Run the following command to make the configurations immediately take effect:
flush privileges;
Run the following command to exit MySQL:
\q
Step 3: Use DMS to connect to the MySQL database
Log on to the DMS console.
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.
In the Add Instance dialog box, click the Third-party Cloud/Self-managed tab and then click MySQL.
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.
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.
Click OK. In the lower-right corner of the Add Instance dialog box, click Submit.
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.