Connect to your ApsaraDB RDS for MySQL instance to manage data or deploy services by using Data Management (DMS), a command-line interface (CLI), or a third-party client.
Billing
-
Creating an ApsaraDB RDS for MySQL instance incurs fees for the instance specifications and storage. The fees vary based on parameters such as the billing method, instance series, specifications, storage type, and storage capacity.
-
The fees described in this tutorial do not include the costs of application servers or third-party clients used to connect to the ApsaraDB RDS instance.
Prerequisites
-
You have created an ApsaraDB RDS for MySQL instance, a database, and a privileged account on the instance. For more information, see Step 1: Create an ApsaraDB RDS for MySQL instance and configure a database.
ImportantThis tutorial uses the ApsaraDB RDS for MySQL instance, database, account, and password that you created and configured in the console by following Step 1: Create an ApsaraDB RDS for MySQL instance and configure a database. You can modify them based on your business requirements.
-
If you plan to log on to the database by using DMS, no additional preparation is required.
-
To connect by using a CLI or a client, configure an IP address whitelist for the instance and obtain the internal or public endpoint based on the access type.
Method 1: Log on by using DMS
Data Management (DMS) is an all-in-one data management platform that supports the entire data lifecycle. It provides features such as global data asset management, data governance, database design and development, data integration, data development, and data consumption. DMS is designed to help enterprises efficiently and securely explore the value of data and accelerate digital transformation.
With DMS, you can log on to an ApsaraDB RDS for MySQL instance without configuring an IP address whitelist or selecting an access type.
-
Go to the Instances page. In the top navigation bar, select the region where the instance resides. Then, click the instance ID.
-
Click Log In to go to the DMS logon page.
-
In the Log On to Instance dialog box, enter the logon information, and click Log On.
-
Select Access Mode. This tutorial uses Account + password login as an example.
If you select the KMS Credential Logon option, see Integrate Data Management (DMS) with RDS Credentials.
-
Enter the Database Account and Database Password. This tutorial uses the privileged account
dbuserand a user-defined password as an example. -
Select Control Mode. This tutorial uses Flexible Management - Free Forever as an example.
Note-
Stable Change and Security Collaboration incur fees.
-
Compared to the Flexible Management (Free Forever) control mode, Stable Change and Security Collaboration provide more features and stronger database control capabilities. If you are trying out or evaluating the RDS MySQL product, we recommend that you select the Flexible Management mode.
-
-
-
View the database. After you log on successfully, you can view the newly created database under Instances Connected on the left side of the DMS page. This tutorial uses the
db_test1database as an example. You can also double-click other databases to switch.Note-
information_schema, MySQL, performance_schema, sys, and Recycle Bin are all system databases.
-
If the instance appears but the database does not show when you expand it, check for these possible causes:
-
The login account does not have access permissions for the target database: You can go to the Accounts page on the RDS instance details page to manually adjust account permissions.
-
The metadata is not synchronized. As a result, the database is not displayed in the navigation tree. You can hover over the instance you want to manage and click the
icon to the right of the instance name to refresh the database list.
To quickly synchronize the database schema, use the schema design feature of DMS.
-
-
Method 2: Connect by using the CLI
Use the MySQL CLI to connect to your ApsaraDB RDS for MySQL instance from an ECS instance or a local server. The following example uses Linux.
-
Before you connect to the instance by using the CLI, you must configure an IP address whitelist for the instance and obtain the required endpoint.
-
You must install MySQL on your application server. The following commands show how to install MySQL on different Linux distributions:
-
CentOS
sudo yum install mysql -
Ubuntu
sudo apt-get update sudo apt install mysql-server
-
-
Log on to the application server that you want to use to connect to the ApsaraDB RDS instance. You can connect from a local server or log on to an Alibaba Cloud ECS instance.
-
Run the database connection command and enter the password to access the ApsaraDB RDS for MySQL instance. In the command,
-hspecifies the endpoint of the ApsaraDB RDS instance,-Pspecifies the port of the ApsaraDB RDS instance,-uspecifies the username, and-pprompts you for the password.# Connection command template mysql -h <endpoint> -P <port> -u <username> -p # Connection command example mysql -h rm-bp**************.mysql.rds.aliyuncs.com -P 3306 -u dbuser -p-
Enter the endpoint. You must determine whether the requirements for an internal connection are met and enter the appropriate endpoint. This tutorial uses an internal endpoint as an example. For more information about how to obtain the internal and public endpoints of an instance, see the Prerequisites section of this topic.
-
Enter the port. This tutorial uses port
3306as an example. -
Enter the username. This tutorial uses the privileged account
dbuseras an example. -
Press the Enter key. At the Enter password prompt, enter the password of the privileged account and press the Enter key again.
-
-
When the CLI displays the following welcome message, you are connected to the ApsaraDB RDS for MySQL instance. You can then perform database operations.
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 51325 Server version: 8.0.18 Source distribution
Method 3: Connect by using a client
Use a third-party database client to connect to your ApsaraDB RDS for MySQL instance. The following example uses MySQL Workbench 8.0.29.
-
Before you connect to the instance by using a client, you must configure an IP address whitelist for the instance and obtain the required endpoint.
-
If you use MySQL Workbench on Windows, installation may fail due to missing system runtime libraries. Visit the official website of the client tool to check its installation guide and system requirements.
-
Open MySQL Workbench and choose Database > Connect to Database.
-
On the Connect to Database page, enter the required endpoint and account information.
-
For Connection Method, select Standard(TCP/IP), which is used as an example in this tutorial.
-
Hostname: You must determine whether the requirements for an internal connection are met and enter the appropriate endpoint. This tutorial uses an internal endpoint as an example.
-
Port: This tutorial uses port
3306as an example. -
Username: This tutorial uses the privileged account
dbuseras an example. -
Password: Enter your custom password.
-
-
Click OK to connect to the ApsaraDB RDS for MySQL instance. You can then perform database operations.
Common errors
FAQ
-
Q: I use Function Compute (FC). How can I retrieve data from an ApsaraDB RDS instance?
A: You can install third-party dependencies for a function and use built-in modules to retrieve data from the ApsaraDB RDS instance. For more information, see Install third-party dependencies for a function.
-
Q: After I connect to the database, how do I import an SQL file?
A: If you need to quickly import a large amount of data from a file (in the SQL, CSV, or Excel format), you can use the data import feature of DMS.
Related documents
-
Database connection failures: Troubleshoot issues that cause connection failures to an ApsaraDB RDS instance
-
Connect to instances that run other database engines: