After creating an ApsaraDB RDS for MySQL instance and a database, you must connect to the instance to manage data or connect your application server to the database to deploy services. This tutorial demonstrates how to log on directly with Data Management (DMS) or connect remotely with a command-line interface (CLI) or a client. Choose the method that best fits your needs.
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. You can proceed directly to the logon steps.
If you plan to connect to the database by using a command-line interface (CLI) or a client, you must configure an IP address whitelist for the instance and obtain the internal or public endpoint based on the access type. The following section describes the required operations:
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.
You can use DMS to quickly and easily log on to an ApsaraDB RDS for MySQL instance to manage and use data. You do not need to configure an IP address whitelist for the instance or select 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.
NoteStable 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.Noteinformation_schema, MySQL, performance_schema, sys, and Recycle Bin are all system databases.
If the instance is listed but the destination database does not appear when you expand it, one of the following may be the cause:
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, you can use the schema design feature of DMS.
Method 2: Connect by using the CLI
If you prefer to use commands to manage your database and want to connect from an Alibaba Cloud ECS instance or a local server, you can connect to your ApsaraDB RDS for MySQL instance by using the CLI. This tutorial uses a Linux operating system as an example.
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 mysqlUbuntu
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 -pEnter 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
If you are not familiar with server commands, you can connect to your ApsaraDB RDS for MySQL instance by using a standard third-party client. This tutorial uses MySQL Workbench 8.0.29 as an example.
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.
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.
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: