What is MySQL event?
MySQL event is the MySQL event scheduler and can be periodically executed. It is a bit like crontab in Linux, but MySQL event can be accurate to seconds. After using the event, you can partially replace the scheduled execution of crontab. However, you do not know if the event is stable or unstable.
1. Check whether MySQL event is enabled.
View copy print?
- Mysql> show variables like"Event %";
- + ----------------- + ------- +
- | Variable_name | value |
- + ----------------- + ------- +
- | Event_scheduler | off |
- + ----------------- + ------- +
- 1 row in Set
If not, set global event_schedld = 1; or add event_schedld = 1 to [mysqld] In my. CNF to save and restart MySQL.
II. A simple example
View copy print?
-
- Create Table: Create Table 'test '(// Test table
-
- 'Time' varchar (20) default null
-
- ) Engine = MyISAM default charset = Latin1
-
- 1 row in SET (0.00 Sec)
-
-
- // Create an event
- Mysql> Create event if not exists test_event on schedule every 5 secondDoInsert into test (time) values (now ());
-
- Query OK, 0 rows affected
-
-
- Mysql> select * from test;// View data
-
- + --------------------- +
-
- | Time |
-
- + --------------------- +
-
- | 09:14:52 |
- + --------------------- +
-
- | 09:14:57 |
-
- + --------------------- +
-
- 2 row in Set