日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql 数据库event_mysql数据库事件调度(Event)

發(fā)布時(shí)間:2025/3/15 数据库 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 数据库event_mysql数据库事件调度(Event) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Oracle數(shù)據(jù)庫(kù)監(jiān)控軟件(簡(jiǎn)稱Oracle監(jiān)控或Oracle監(jiān)控軟件)是企事業(yè)單位中最重要的監(jiān)控需要,通過(guò)對(duì)Oracle數(shù)據(jù)庫(kù)的監(jiān)控,可以全面了解Oracle的運(yùn)行狀態(tài)、數(shù)據(jù)庫(kù)響應(yīng)情況、數(shù)據(jù)庫(kù)表空用度情況。

SUM服務(wù)器監(jiān)控軟件對(duì)Oracle數(shù)據(jù)庫(kù)的監(jiān)控十分全面,主要有:緩沖區(qū)命中率監(jiān)控、表空間使用率監(jiān)控、表空間監(jiān)控、會(huì)話數(shù)監(jiān)控、連接數(shù)監(jiān)控等核心性能,這些性能均為DBA必須了解和隨時(shí)掌握的性能,SUM的監(jiān)控為DBA提供了有力的幫助。在Oracle數(shù)據(jù)庫(kù)的性能監(jiān)控中其中表空間隨時(shí)監(jiān)控是DBA首要職責(zé),因?yàn)橐坏┍砜沼帽M,將無(wú)法再進(jìn)行數(shù)據(jù)庫(kù)的操作,這將給應(yīng)用軟件造成很大的損失。通過(guò)SUM監(jiān)控與短信報(bào)警功能,DBA可以設(shè)定表空間使用率閥值進(jìn)行報(bào)警,比如可以設(shè)定表空間使用率達(dá)到95%后就立即短信通知指定的DBA進(jìn)行表空間擴(kuò)容,從而可以有效地避免因?yàn)楸砜臻g不足引起的應(yīng)用程序錯(cuò)誤和數(shù)據(jù)庫(kù)錯(cuò)誤。

mysql中的事件調(diào)度器可以定時(shí)對(duì)數(shù)據(jù)庫(kù)增加,刪除和執(zhí)行操作,相當(dāng)于數(shù)據(jù)庫(kù)中的臨時(shí)觸發(fā)器,與Linux系統(tǒng)中的執(zhí)行計(jì)劃任務(wù)一樣,這樣就可以大大降低工作量.

1.開(kāi)啟事件調(diào)度器

[root@node1 ~]# vim /usr/my.cnf???????? --在配置文件中加入以下語(yǔ)句啟用調(diào)度器

event_scheduler=1

[root@node1 ~]# /etc/init.d/mysql restart

ERROR! MySQL server PID file could not be found!

Starting MySQL... SUCCESS!

[root@node1 ~]#

2.查看事件調(diào)度是否開(kāi)啟

[root@node1 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like "event_%";?????????? --查看調(diào)度器是否啟用

+-----------------+-------+

| Variable_name?? | Value |

+-----------------+-------+

| event_scheduler | ON??? |

+-----------------+-------+

1 row in set (0.00 sec)

mysql> ? create event;????????????? --查看創(chuàng)建事件的語(yǔ)法

Name: 'CREATE EVENT'

Description:

Syntax:

CREATE

[DEFINER = { user | CURRENT_USER }]

EVENT

[IF NOT EXISTS]

event_name

ON SCHEDULE schedule

[ON COMPLETION [NOT] PRESERVE]

[ENABLE | DISABLE | DISABLE ON SLAVE]

[COMMENT 'comment']

DO event_body;

schedule:

AT timestamp [+ INTERVAL interval] ...

| EVERY interval

[STARTS timestamp [+ INTERVAL interval] ...]

[ENDS timestamp [+ INTERVAL interval] ...]

interval:

quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |

WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |

DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

mysql> create database test123;

Query OK, 1 row affected (0.00 sec)

mysql> \u test123

Database changed

mysql>

3.創(chuàng)建事件調(diào)度5秒鐘后創(chuàng)建t表

mysql> create event if not exists event_t on schedule at current_timestamp + interval 5 second? do create table t (a int,b nchar(10),c timestamp);

Query OK, 0 rows affected (0.00 sec)

mysql> show events;??????? --查看事件是否創(chuàng)建成功

+---------+----------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+

| Db????? | Name???? | Definer??????? | Time zone | Type????? | Execute at | Interval value | Interval field | Starts????????????? | Ends | Status? | Originator | character_set_client | collation_connection | Database Collation |

+---------+----------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+

| test123 | event_t1 |?root@localhost?| SYSTEM??? | RECURRING | NULL?????? | 5????????????? | SECOND???????? | 2014-11-12 15:29:13 | NULL | ENABLED |????????? 0 | utf8???????????????? | utf8_general_ci????? | latin1_swedish_ci? |

+---------+----------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+

1 row in set (0.00 sec)

mysql> show tables;

Empty set (0.00 sec)

mysql> show tables;?????????????? --創(chuàng)建表成功

+-------------------+

| Tables_in_test123 |

+-------------------+

| t???????????????? |

+-------------------+

1 row in set (0.00 sec)

mysql> desc t;

+-------+-----------+------+-----+-------------------+-----------------------------+

| Field | Type????? | Null | Key | Default?????????? | Extra?????????????????????? |

+-------+-----------+------+-----+-------------------+-----------------------------+

| a???? | int(11)?? | YES? |???? | NULL????????????? |???????????????????????????? |

| b???? | char(10)? | YES? |???? | NULL????????????? |???????????????????????????? |

| c???? | timestamp | NO?? |???? | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |

+-------+-----------+------+-----+-------------------+-----------------------------+

3 rows in set (0.01 sec)

mysql>

4.創(chuàng)建事件調(diào)度每5秒在表中插入數(shù)據(jù)

mysql> create event if not exists event_t1 on schedule every? 5 second? do insert into t values(1,1,sysdate());

Query OK, 0 rows affected (0.01 sec)

mysql> select * from t;?????????? --查看事件執(zhí)行數(shù)據(jù)

+------+------+---------------------+

| a??? | b??? | c?????????????????? |

+------+------+---------------------+

|??? 1 | 1??? | 2014-11-12 15:33:31 |

|??? 1 | 1??? | 2014-11-12 15:33:36 |

|??? 1 | 1??? | 2014-11-12 15:33:41 |

|??? 1 | 1??? | 2014-11-12 15:33:46 |

|??? 1 | 1??? | 2014-11-12 15:33:51 |

|??? 1 | 1??? | 2014-11-12 15:33:56 |

|??? 1 | 1??? | 2014-11-12 15:34:01 |

+------+------+---------------------+

7 rows in set (0.00 sec)

mysql>

5.創(chuàng)建事件調(diào)度10秒鐘后刪除t表中所有數(shù)據(jù)

mysql> create event if not exists event_t2 on schedule every? 10? second? do truncate table t;

Query OK, 0 rows affected (0.00 sec)

mysql> select * from t;

+------+------+---------------------+

| a??? | b??? | c?????????????????? |

+------+------+---------------------+

|??? 1 | 1??? | 2014-11-12 15:36:36 |

|??? 1 | 1??? | 2014-11-12 15:36:41 |

+------+------+---------------------+

2 rows in set (0.00 sec)

mysql> select * from t;

Empty set (0.00 sec)

mysql>

6.在指定時(shí)間刪除t表數(shù)據(jù)

mysql> create event if not exists event_t2 on schedule at timestamp '2014-11-12 15:39:00' do truncate table t;;

Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> select * from t;

Empty set (0.00 sec)

mysql>

7.創(chuàng)建事件調(diào)度每天刪除t表數(shù)據(jù)

mysql> create event if not exists event_t2 on schedule every 1 day? do truncate table t;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select * from t;

Empty set (0.00 sec)

mysql>

8.創(chuàng)建事件調(diào)度5天后開(kāi)啟刪除t表中數(shù)據(jù),一個(gè)月后停止

mysql> create event if not exists event_t2 on schedule every 1 day? starts current_timestamp + interval 5 day ends current_timestamp + interval 1 month do truncate table t;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

9.禁用事件調(diào)度器

mysql> alter? event event_t2 disable;

Query OK, 0 rows affected (0.00 sec)

mysql>

10.啟用事件調(diào)度器

mysql> alter? event event_t2 enable;

Query OK, 0 rows affected (0.00 sec)

mysql>

11.修改事件調(diào)度器10天后啟用

mysql> alter? event event_t2 on schedule every 10 day;

Query OK, 0 rows affected (0.00 sec)

mysql>

12.重命名事件調(diào)度器

mysql> alter event event_t2 rename to event_t1;

Query OK, 0 rows affected (0.00 sec)

mysql>

13.查看事件調(diào)度器的信息

mysql> show events like "event_t1" \G;

*************************** 1. row ***************************

Db: test123

Name: event_t1

Definer:?root@localhost

Time zone: SYSTEM

Type: RECURRING

Execute at: NULL

Interval value: 10

Interval field: DAY

Starts: 2014-11-12 15:47:31

Ends: NULL

Status: ENABLED

Originator: 0

character_set_client: utf8

collation_connection: utf8_general_ci

Database Collation: latin1_swedish_ci

1 row in set (0.00 sec)

ERROR:

No query specified

mysql>

14.查看事件調(diào)度器的內(nèi)容

mysql> show create event event_t1 \G;

*************************** 1. row ***************************

Event: event_t1

sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

time_zone: SYSTEM

Create Event: CREATE?DEFINER=`root`@`localhost` EVENT `event_t1` ON SCHEDULE EVERY 10 DAY STARTS '2014-11-12 15:47:31' ON COMPLETION NOT PRESERVE ENABLE DO truncate table t

character_set_client: utf8

collation_connection: utf8_general_ci

Database Collation: latin1_swedish_ci

1 row in set (0.00 sec)

ERROR:

No query specified

mysql>

總結(jié)

以上是生活随笔為你收集整理的mysql 数据库event_mysql数据库事件调度(Event)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。