MySQLÖÐselect * for updateËø±íµÄÎÊÌâ
select * for updateËø±íµÄÎÊÌâ
ÓÉÓÚInnoDBÔ¤ÉèÊÇRow-Level Lock£¬ËùÒÔÖ»ÓС¸Ã÷È·¡¹µÄÖ¸¶¨Ö÷¼ü£¬MySQL²Å»áÖ´ÐÐRow lock (Ö»Ëø×¡±»Ñ¡È¡µÄ×ÊÁÏÀý) £¬·ñÔòMySQL½«»áÖ´ÐÐTable Lock (½«Õû¸ö×ÊÁÏ±íµ¥¸øËø×¡)¡£
¾Ù¸öÀý×Ó:
¼ÙÉèÓиö±íµ¥products £¬ÀïÃæÓÐid¸úname¶þ¸öÀ¸Î»£¬idÊÇÖ÷¼ü¡£
Àý1: (Ã÷È·Ö¸¶¨Ö÷¼ü£¬²¢ÇÒÓд˱Ê×ÊÁÏ£¬row lock)
SELECT * from products WHERE id='3' FOR UPDATE;
Àý2: (Ã÷È·Ö¸¶¨Ö÷¼ü£¬Èô²éÎ޴˱Ê×ÊÁÏ£¬ÎÞlock)
SELECT * from products WHERE id='-1' FOR UPDATE;
Àý2: (ÎÞÖ÷¼ü£¬table lock)
SELECT * from products WHERE name='Mouse' FOR UPDATE;
Àý3: (Ö÷¼ü²»Ã÷È·£¬table lock)
SELECT * from products WHERE id<>'3' FOR UPDATE;
Àý4: (Ö÷¼ü²»Ã÷È·£¬table lock)
SELECT * from products WHERE id LIKE '3' FOR UPDATE;
×¢1: FOR UPDATE½öÊÊÓÃÓÚInnoDB£¬ÇÒ±ØÐëÔÚ½»Ò×Çø¿é(BEGIN/COMMIT)ÖвÅÄÜÉúЧ¡£
×¢2: Òª²âÊÔ
Ëø¶¨µÄ×´¿ö£¬¿ÉÒÔÀûÓÃMySQLµÄCommand Mode £¬¿ª¶þ¸öÊÓ´°À´×ö²âÊÔ¡£
Ïà¹ØÎĵµ£º
ÒÔÏÂÊÇÉæ¼°µ½²åÈë±í¸ñµÄ²éѯµÄ5ÖָĽø·½·¨£º
1)ʹÓÃLOAD DATA INFILE´ÓÎı¾ÏÂÔØÊý¾ÝÕ⽫±ÈʹÓòåÈëÓï¾ä¿ì20±¶¡£
2)ʹÓôøÓжà¸öVALUESÁбíµÄINSERTÓï¾äÒ»´Î²åÈ뼸ÐÐÕ⽫±ÈʹÓÃÒ»¸öµ¥ÐвåÈëÓï¾ä¿ì¼¸±¶¡£µ÷Õûbulk_insert_buffer_size±äÁ¿Ò²ÄÜÌá¸ß£¨Ïò°üº¬Ðеıí¸ñÖУ©²åÈëµÄËÙ¶È¡£
3)¿ÉÒÔ¶Ômyisam±í²¢ÐвåÈëConcurrent_i ......
1.INµÄÓ÷¨
IN(value,value1,...) valuesµÄ¸öÊý¸úmax_allowed_packetÏà¹Ø£¬SELECT 2 IN (2,4,'STRING');
NOT IN(value,..)ºÍINÓï·¨Ò»Ñù¡£
2.IF NOT EXISTS
CREATE ... IF NOT EXISTS stm; ...¿ÉÒÔʹDATABASE,TABLE,EVENT¡£ÈçCREATE TABLE IF NOT EXISTS t(id INT);
3.MD5,MySQLÊý¾Ý¿âÌṩÁËmd5¼ÓÃܹ¦Ä ......
1.MySQL´´½¨ÊÓͼµÄ¼òµ¥Óï¾äΪ£ºCREATE VIEW view_name AS SELECT * from TABLE_NAME;
²»ÄܶԴ¥·¢Æ÷´´½¨ÊÓͼ(VIEW)¡£µ«ÊÇÔÚ5.1.4ÖÐÊÇÕâÑùÃèÊöµÄ£¬A view can be created from many kinds of SELECT statements. It can refer to base tables or other views. It can use joins, UNION, and subqueries¡£´óÖÂÒâ˼ÊÇÊÓÍ ......
create procedure getInfor2()
BEGIN
declare _abc varchar(200);
declare stopFlag int;
DECLARE cursor_name CURSOR
FOR
select zhuanyuan from server;
DECLARE CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;
OPEN cursor_name;
REPEAT
FETCH cursor_name INTO _abc;
begin
if _abc='root'
the ......