[MySQL 5.1 ÌåÑé]MySQL ʼþµ÷¶ÈÆ÷(Event Scheduler)
http://hi.baidu.com/tianxia_1209/blog/item/a2613822fec7e7f6d6cae267.html
MYSQLµÄʼþÊÇ5.1ÐÂÔö¼ÓµÄ£¬Èç¹ûÏëÌåÑ飬½¨ÒéÉý¼¶°æ±¾¡£
ÖÁÓÚÓï·¨ÎҾͲ»¶à˵ÁË£¬ÊÖ²áÉϽ²µÄºÜÏêϸ£¬ÎÒÀ´ËµËµ¼¸¸öÒªµãÒÔ¼°Ò»Ð©ÊµÀý¡£
×¢ÒâÊÂÏ
1¡¢EVENTȨÏÞÊÇÕë¶ÔģʽµÄ£¨ÔÚMYSQLÖÐÒ²¾ÍÊÇ¿âµÄ¼¶±ð£©£¬²»ÄܶԵ¥¶À±íÀ´¸³ÓèȨÏÞ¡£
2¡¢±ØÐëÔÚÈ«¾Ö¿ªÆô¡£
3¡¢ÐÔÄÜÉϵÄËðʧһ¶¨µÃ¿¼Âǵ½¡£
mysql> show variables like '%event%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | OFF |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> set global event_scheduler = on;
Query OK, 0 rows affected (0.00 sec)
mysql> use event;
Database changed
Àý×Ó£º
ÎÒÃÇÀ´´´½¨Ò»¸ö¼òµ¥µÄÎÄÕÂ±í£º
mysql> create table article (id serial,title varchar(64) not null, author_name varchar(64),content mediumtext not null, create_time datetime not null,update_time datetime not null);
Query OK, 0 rows affected (0.01 sec)
ÒÔ¼°Í³¼Æ±í£º
mysql> create table report (id int not null auto_increment primary key, r_date date not null,aid int not null,total int not null);
Query OK, 0 rows affected (0.01 sec)
mysql> ²åÈë²âÊÔÊý¾Ý¡£¡£¡£
ÎÒÃÇÀ´½¨Á¢Ò»¸ö´æ´¢¹ý³Ì¡£
mysql> delimiter ||
mysql> create procedure sp_report()
-> begin
-> insert into report(r_date,aid,total) select date(update_time) as r_date, id,count(1) from article group by date(create_time) order by r_date asc;
-> end||
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
´´½¨EVENT;
ÔÚÒ»·ÖÖÓºóÖ´ÐÐÕâ¸ö´æ´¢¹ý³Ì¡£
mysql> create event report_dawn on schedule at date_add(now(),interval 1 minute) on completion preserve do call sp_report();
Query OK, 0 rows affected (0.00 sec)
mysql> show processlist;
| 7 | event_scheduler | localhost | NULL | Daemon | 5 | Waiting for next activation | NULL 
Ïà¹ØÎĵµ£º
´ÓºËÌÒ²©¿Í
תÔØ£¬
ÓÑÇéÎÊ´ð2-mysqlÔõôȡ³ö×îÐÂÔö¼ÓµÄÊý¾Ý
ÔÚhttp://zhidao.baidu.com/question/131093225.html
ÓÐÈËÎÊ“mysqlÔõôȡ³ö×îÐÂÔö¼ÓµÄÊý¾Ý”£¬
ÆäʵÕýÈ·µÄ·½Ê½Êǽ«×ֶζ¨Òå³Éint primary key
auto_increment£¬È»ºóÓÃlast_insert_id()È¡³öÀ´£¬ÒòΪÕâÊÇÃæÏòÁ¬½ÓµÄ£¬Ḭ̈߳²È«µÄ£¬Èç¹ûÈ¡max(id)ÕâÑ ......
InnoDB
ºÍMyISAM
ÊÇÔÚʹÓÃMySQL
×î³£ÓõÄÁ½¸ö±íÀàÐÍ£¬¸÷ÓÐÓÅȱµã£¬ÊÓ¾ßÌåÓ¦Óöø¶¨¡£»ù±¾µÄ²î±ðΪ£ºMyISAM
ÀàÐͲ»Ö§³ÖÊÂÎñ´¦ÀíµÈ¸ß¼¶´¦Àí£¬¶øInnoDB
ÀàÐÍÖ§³Ö¡£MyISAM
ÀàÐ͵ıíÇ¿µ÷µÄÊÇÐÔÄÜ£¬ÆäÖ´ÐÐÊý¶È±ÈInnoDB
ÀàÐ͸ü¿ì£¬µ«ÊDz»ÌṩÊÂÎñÖ§³Ö£¬¶øInnoDB
ÌṩÊÂÎñÖ§³ÖÒѾÍⲿ¼üµÈ¸ß¼¶Êý¾Ý¿â¹¦ÄÜ¡£
MyIASMÊÇIASM± ......
ʹÓÃÕûÊýÊý¾ÝµÄ¾«È·Êý×ÖÊý¾ÝÀàÐÍ¡£
bigint
´Ó -2^63 (-9223372036854775808) µ½ 2^63-1 (9223372036854775807) µÄÕûÐÍÊý¾Ý£¨ËùÓÐÊý×Ö£©¡£´æ´¢´óСΪ 8 ¸ö×Ö½Ú¡£
int
´Ó -2^31 (-2,147,483,648) µ½ 2^31 - 1 (2,147,483,647) µÄÕûÐÍÊý¾Ý£¨ËùÓÐÊý×Ö£©¡£´æ´¢´óСΪ 4 ¸ö×Ö½Ú¡£int µÄ SQL-92 ͬÒå×ÖΪ integer¡£
smallin ......
MySQL ÃüÁîÐÐ
µÚÒ»ÕС¢mysql·þÎñµÄÆô¶¯ºÍÍ£Ö¹
net stop mysql
net start mysql
µÚ¶þÕС¢µÇ½mysql
Óï·¨ÈçÏ£º mysql -uÓû§Ãû -pÓû§ÃÜÂë
¼üÈëÃüÁîmysql -uroot -p£¬ »Ø³µºóÌáʾÄãÊäÈëÃÜÂ룬ÊäÈë12345£¬È»ºó»Ø³µ¼´¿É½øÈëµ½mysqlÖÐÁË£¬mysqlµÄÌáʾ·ûÊÇ£º
mysql>
×¢Ò⣬Èç¹ûÊÇÁ¬½Óµ½ÁíÍâµÄ»úÆ÷ÉÏ£¬ÔòÐèÒª¼ÓÈëÒ»¸ö² ......