MySQL ROUTINE & EVENT
ROUTINE(procedure&funcation)
建立:
Create procedure|function sp
修改
Alter procedure|function sp
呼叫
Call sp(param)
建立sp前指定:DELIMITER $$ 將語句結束的; 替代
DELIMITER $$
CREATE PROCEDURE SP()
…
End $$
DELIMITER;
增加trigger,限制delete操作
DELIMITER $$
CREATE TRIGGER test1.tri
BEFORE DELETE ON test1.emp
FOR EACH ROW
BEGIN
DECLARE msg varchar(50) ;
SET msg = "table記錄無法刪除";
SIGNAL SQLSTATE 'HY000' SET mysql_errno = 22, message_text = msg;
END;$$
delimiter ;
說明:HY000為系統內部錯誤號,22為自定義的顯示錯誤號,msg為錯誤文字
檢視狀態
Show procedure status like ‘xxx’
檢視定義
Show procedure xxx;
檢視資料字典
select * from information_schema.routines
EVENT(schedule)
類似oracle job
建立
create event myevent
on schedule every 1 hour
do
update emp1 set emp_no=emp_no+1;
檢視狀態
mysql> show events\G;
*************************** 1. row ***************************
Db: test1
Name: myevent
Definer: root@localhost
Time zone: SYSTEM
Type: ONE TIME
Execute at: 2016-10-14 12:10:53
Interval value: NULL
Interval field: NULL
Starts: NULL
Ends: NULL
Status: ENABLED
Originator: 0
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8_general_ci
1 row in set (0.01 sec)
開啟排程器,預設關閉:
mysql> show variables like '%schedule%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | OFF |
+-----------------+-------+
mysql> set global event_scheduler=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show processlist \G;
*************************** 4. row ***************************
Id: 17
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time: 62
State: Waiting on empty queue
Info: NULL
禁用:
mysql> alter event myevent disable;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-2152060/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql中 routineMySql
- mysql 事件 eventMySql事件
- MySQL入門--EVENT(事件)MySql事件
- mysql的mysql.event和information_schema.eventsMySqlORM
- Mysql 關於event的詳解MySql
- MySQL中的事件排程器EVENTMySql事件
- MySQL [ERROR] Slave I/O: Found a Gtid_log_event or Previous_gtids_log_eventMySqlError
- MySQL的事件溯源Event Sourcing表結構MySql事件
- MySQL 伺服器啟用 event_schedulerMySql伺服器
- MySQL定時器EVENT學習筆記MySql定時器筆記
- event_x ()、event_y ()、event_x_root ()、event_y_root ()
- event.preventDefault()和event.stopPropagation()
- 隨筆:MySQL:雙主情況下跳過Event的方式MySql
- MySQL使用event等待事件進行資料庫效能診斷MySql事件資料庫
- Added non-passive event listener to ascroll- blocking ‘mousewheel‘event Consider marking event handlBloCIDE
- JavaScript EventJavaScript
- Event 2024.6.18
- Event loopOOP
- 詳解 MySQL 用事件排程器 Event Scheduler 建立定時任務MySql事件
- MySQL案例01:Last_SQL_Errno: 1755 Cannot execute the current event group in the parallel modeMySqlASTParallel
- 詳解MySQL用事件排程器Event Scheduler建立定時任務MySql事件
- event.relatedTarget
- ORACLE EVENT && ORADEBUGOracle
- javascript - event loopJavaScriptOOP
- Event Reference(zt)
- node event loopOOP
- epoll_event
- JavaScript Event LoopJavaScriptOOP
- javascript event visualizeJavaScript
- libevent之event
- Event,EventTarget,EventEmitterMIT
- event loop整理OOP
- 瀏覽器的event loop和node的event loop瀏覽器OOP
- 瀏覽器event loop和node的event loop講解瀏覽器OOP
- JavaScript event.typeJavaScript
- 淺談event loopOOP
- JavaScript event.timeStampJavaScript
- JavaScript event.keyCodeJavaScript