MySQL 5.5建立和檢視資料庫計劃任務(event)
--檢視相關引數
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | OFF |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--開啟相關引數
mysql> set global event_scheduler = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | ON |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--開啟引數後,線上程中會出現event_scheduler相關執行緒
mysql> show processlist\G
*************************** 7. row ***************************
Id: 13
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time: 474
State: Waiting for next activation
Info: NULL
7 rows in set (0.00 sec)
--建立計劃任務
mysql> CREATE EVENT myevent
-> ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
-> DO
-> UPDATE fire.t12 SET sal = sal + 100;
Query OK, 0 rows affected (0.02 sec)
--檢視資料庫裡面的計劃任務
mysql> show events from fire\G
*************************** 1. row ***************************
Db: fire
Name: myevent
Definer: system@localhost
Time zone: SYSTEM
Type: ONE TIME
Execute at: 2016-05-23 02:48:03
Interval value: NULL
Interval field: NULL
Starts: NULL
Ends: NULL
Status: ENABLED
Originator: 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--檢視計劃任務的內容
mysql> show create event myevent\G
*************************** 1. row ***************************
Event: myevent
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE DEFINER=`system`@`localhost` EVENT `myevent` ON SCHEDULE AT '2016-05-23 02:48:03' ON COMPLETION NOT PRESERVE ENABLE DO UPDATE fire.t12 SET sal = sal + 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--禁止計劃任務
mysql> ALTER EVENT myevent DISABLE;
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | OFF |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--開啟相關引數
mysql> set global event_scheduler = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | ON |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--開啟引數後,線上程中會出現event_scheduler相關執行緒
mysql> show processlist\G
*************************** 7. row ***************************
Id: 13
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time: 474
State: Waiting for next activation
Info: NULL
7 rows in set (0.00 sec)
--建立計劃任務
mysql> CREATE EVENT myevent
-> ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
-> DO
-> UPDATE fire.t12 SET sal = sal + 100;
Query OK, 0 rows affected (0.02 sec)
--檢視資料庫裡面的計劃任務
mysql> show events from fire\G
*************************** 1. row ***************************
Db: fire
Name: myevent
Definer: system@localhost
Time zone: SYSTEM
Type: ONE TIME
Execute at: 2016-05-23 02:48:03
Interval value: NULL
Interval field: NULL
Starts: NULL
Ends: NULL
Status: ENABLED
Originator: 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--檢視計劃任務的內容
mysql> show create event myevent\G
*************************** 1. row ***************************
Event: myevent
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE DEFINER=`system`@`localhost` EVENT `myevent` ON SCHEDULE AT '2016-05-23 02:48:03' ON COMPLETION NOT PRESERVE ENABLE DO UPDATE fire.t12 SET sal = sal + 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--禁止計劃任務
mysql> ALTER EVENT myevent DISABLE;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2105493/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql計劃任務:event scheduleMySql
- 使用 Laravel 制定 MySQL 資料庫備份計劃任務LaravelMySql資料庫
- mysql和oracle計劃任務MySqlOracle
- MySQL資料庫檢視:檢視定義、建立檢視、修改檢視MySql資料庫
- MySQL 5.5 檢視分割槽表的執行計劃MySql
- mysql計劃任務MySql
- 如何檢視資料庫中的job任務資料庫
- ORACLE資料庫檢視執行計劃Oracle資料庫
- 1.2.4. 任務4:建立和開啟資料庫資料庫
- 資料庫無法建立資料庫檢視資料庫
- 2.2.1 資料庫建立計劃資料庫
- 配置計劃任務定期清理資料庫trc檔案資料庫
- 使用set autotrace on 檢視資料庫執行計劃資料庫
- 1.2.3. 任務3:資料庫規劃資料庫
- Event Loop、 巨集任務和微任務OOP
- mysql建立索引和檢視MySql索引
- MySQL檢視當前資料庫庫MySql資料庫
- 達夢資料庫SQL執行計劃檢視方法資料庫SQL
- 資料庫篇:mysql事務原理之MVCC檢視+鎖資料庫MySqlMVC
- 檢視MySQL資料庫的命令MySql資料庫
- rhel4 mysql 5.5_檢視業務資料庫的表名及表列_管理MySql資料庫
- MySQL命令檢視資料庫和表容量大小MySql資料庫
- 檢視和設定MySQL資料庫字符集MySql資料庫
- 計劃任務
- 詳解 MySQL 用事件排程器 Event Scheduler 建立定時任務MySql事件
- 詳解MySQL用事件排程器Event Scheduler建立定時任務MySql事件
- mysql binlog檢視指定資料庫MySql資料庫
- 詳述Linux計劃任務的 at和crontab的命令 以及如何檢視crontab日誌Linux
- MySQL 建立檢視MySql
- 計劃任務(CRON)
- 計劃任務crontab
- 2.8.3 資料庫服務的資料字典檢視資料庫
- 使用at和cron實現任務計劃
- mysql 建立定時任務MySql
- mysql建立定時任務MySql
- 1.2.7. 任務7:資料庫設計資料庫
- 用SQL命令檢視Mysql資料庫大小MySql資料庫
- Mysql 5.5 設定資料庫引數MySql資料庫