Configuring a Scheduled Event for an RDS for MySQL Instance
When you need to execute scheduled or periodic tasks in an RDS for MySQL instance, such as scheduled data synchronization, regular expired data deletion, and periodic data insertion, you can enable the event scheduler and configure a scheduled event in Data Admin Service (DAS) to automatically execute events defined in the instance based on the scheduled plan. This section describes how to use DAS to configure a scheduled event for an RDS for MySQL instance.
Constraints
- The event scheduler can be enabled only for DB instances running MySQL 5.6.43.2 or later, 5.7.25.2 or later, and 8.0.17.4 or later. If your DB engine version is beyond the above range, to use this function, upgrade the minor version first.
- The event scheduler cannot be enabled for read replicas.
Step 1: Enable the Event Scheduler
- Log in to the management console.
- Click
in the upper left corner and select a region.
- Click
in the upper left corner of the page and choose Databases > Relational Database Service.
- On the Instances page, click the DB instance name.
- On the Overview page, click Enable under Event Scheduler.
Step 2: Configure a Scheduled Event
- On the Instances page, locate the DB instance and click Log In in the Operation column.
Figure 1 Logging in to an instance
- Enter root and its password, and click Log In.
Figure 2 Login page
- Choose SQL Operations > SQL Query.
- In the SQL window, create a database named db_test.
create database db_test;
Figure 3 Creating a database - Create a table named t_test in the db_test database.
create table t_test(id int(4), name char(20), age int(4));
Figure 4 Creating a table - On the homepage, click the database name.
Figure 5 Homepage
- On the displayed Objects page, choose Events. On the displayed page, click Create Event.
Figure 6 Objects
- Enter the event information and click Create.
Figure 7 Creating an event
Table 1 Event description Parameter
Description
Event Name
Enter a custom event name.
Dropped upon expiration
- If this option is deselected, the event is always retained.
- If you select this option, the event will be deleted upon expiration.
- Events that are executed at a fixed time will be deleted once they are executed.
- Events that are executed at a scheduled time will be deleted at the end time you specify.
Status
To execute an event, select Enable trigger.
Comment
Enter comments for the event.
Execution Time
- Fixed
The event is executed only once at a fixed time.
- Scheduled
The event is executed at an interval you specify between the start time and end time.
For example, an event is executed every minute between 09:50 and 10:00.
Event Definition Statements
Enter the statements to be executed when the event is triggered.
For example, to insert a data record into the t_test table, enter the following statements:
begin insert into t_test(id, name, age) values(1, 'zhangsan', 30); end
- In the displayed dialog box, click Execute to execute the event at the specified time.
- In the object list, locate the table and click Open.
Figure 8 Opening a table
- Check the execution results of the event.
Figure 9 Checking execution results
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot