mysql ÊÂÎñ´¦Àí
¹ØÓÚMySQLÊÂÎñ´¦Àíѧϰ¼Ç
START TRANSACTION, COMMITºÍROLLBACKÓï·¨
START TRANSACTION | BEGIN [WORK]
COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
SET AUTOCOMMIT = {0 | 1}
START
TRANSACTION»òBEGINÓï¾ä¿ÉÒÔ¿ªÊ¼Ò»ÏîеÄÊÂÎñ¡£COMMIT¿ÉÒÔÌá½»µ±Ç°ÊÂÎñ£¬ÊDZä¸ü³ÉΪÓÀ¾Ã±ä¸ü¡£ROLLBACK¿ÉÒÔ
»Ø¹öµ±Ç°ÊÂÎñ£¬È¡ÏûÆä±ä¸ü¡£SET AUTOCOMMITÓï¾ä¿ÉÒÔ½ûÓûòÆôÓÃĬÈϵÄautocommitģʽ£¬ÓÃÓÚµ±Ç°Á¬½Ó¡£
×ÔÑ¡µÄWORK¹Ø¼ü´Ê±»Ö§³Ö£¬ÓÃÓÚCOMMITºÍRELEASE£¬ÓëCHAINºÍRELEASE×Ӿ䡣CHAINºÍRELEASE¿ÉÒÔ±»ÓÃÓÚ¶ÔÊÂÎñÍê³É½øÐи½¼Ó¿ØÖÆ¡£Completion_typeϵͳ±äÁ¿µÄÖµ¾ö¶¨ÁËĬÈÏÍê³ÉµÄÐÔÖÊ¡£
AND
CHAIN×Ó¾ä»áÔÚµ±Ç°ÊÂÎñ½áÊøʱ£¬Á¢¿ÌÆô¶¯Ò»¸öÐÂÊÂÎñ£¬²¢ÇÒÐÂÊÂÎñÓë¸Õ½áÊøµÄÊÂÎñÓÐÏàͬµÄ¸ôÀëµÈ¼¶¡£RELEASE×Ó¾äÔÚÖÕÖ¹Á˵±Ç°ÊÂÎñºó£¬»áÈ÷þÎñÆ÷
¶Ï¿ªÓ뵱ǰ¿Í»§¶ËµÄÁ¬½Ó¡£°üº¬NO¹Ø¼ü´Ê¿ÉÒÔÒÖÖÆCHAIN»òRELEASEÍê³É¡£Èç¹ûcompletion_typeϵͳ±äÁ¿±»ÉèÖÃΪһ¶¨µÄÖµ£¬Ê¹Á¬Ëø
»òÊÍ·ÅÍê³É¿ÉÒÔĬÈϽøÐУ¬´ËʱNO¹Ø¼ü´ÊÓÐÓá£
ĬÈÏÇé¿öÏ£¬MySQL²ÉÓÃautocommitģʽÔËÐС£ÕâÒâζ×Å£¬µ±ÄúÖ´ÐÐÒ»¸öÓÃÓÚ¸üУ¨Ð޸ģ©±íµÄÓï¾äÖ®ºó£¬MySQLÁ¢¿Ì°Ñ¸üд洢µ½´ÅÅÌÖС£
Èç¹ûÄúÕýÔÚʹÓÃÒ»¸öÊÂÎñ°²È«Ð͵Ĵ洢ÒýÇ棨ÈçInnoDB, BDB»òNDB´Ø£©£¬ÔòÄú¿ÉÒÔʹÓÃÒÔÏÂÓï¾ä½ûÓÃautocommitģʽ£º
SET AUTOCOMMIT=0;
ͨ¹ý°ÑAUTOCOMMIT±äÁ¿ÉèÖÃΪÁ㣬½ûÓÃautocommitģʽ֮ºó£¬Äú±ØÐëʹÓÃCOMMIT°Ñ±ä¸ü´æ´¢µ½´ÅÅÌÖУ¬»ò×ÅÈç¹ûÄúÏëÒªºöÂÔ´ÓÊÂÎñ¿ªÊ¼½øÐÐÒÔÀ´×ö³öµÄ±ä¸ü£¬Ê¹ÓÃROLLBACK¡£
Èç¹ûÄúÏëÒª¶ÔÓÚÒ»¸öµ¥Ò»ÏµÁеÄÓï¾ä½ûÓÃautocommitģʽ£¬ÔòÄú¿ÉÒÔʹÓÃSTART TRANSACTIONÓï¾ä£º
START TRANSACTION;
SELECT @A:=SUM(salary) from table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;
ʹÓÃSTART TRANSACTION£¬autocommitÈÔÈ»±»½ûÓã¬Ö±µ½ÄúʹÓÃCOMMIT»òROLLBACK½áÊøÊÂÎñΪֹ¡£È»ºóautocommitģʽ»Ö¸´µ½ÔÀ´µÄ״̬¡£
BEGINºÍBEGIN WORK±»×÷ΪSTART TRANSACTIONµÄ±ðÃûÊܵ½Ö§³Ö£¬ÓÃÓÚ¶ÔÊÂÎñ½øÐгõʼ»¯¡£START
TRANSACTIONÊDZê×¼µÄSQLÓï·¨£¬²¢ÇÒÊÇÆô¶¯Ò»¸öad-hocÊÂÎñµÄÍƼö·½·¨¡£BEGINÓï¾äÓëBEGIN¹Ø¼ü´ÊµÄʹÓò»Í¬¡£BEGIN¹Ø¼ü´Ê
¿ÉÒÔÆô¶¯Ò»¸öBEGIN...END¸´ºÏÓï¾ä¡£ºóÕß²»»á¿ªÊ¼Ò»ÏîÊÂÎñ¡£
ÄúÒ²¿ÉÒÔ°´ÕÕÈçÏ·½·¨¿ªÊ¼Ò»ÏîÊÂÎñ£º
START TRANSACTION WITH CONSISTENT SNAPSHOT;
WITH CONSISTENT
SNAPSHOT×Ó¾äÓ
Ïà¹ØÎĵµ£º
1¡¢Ð½¨±ítest create table test1( field1 int not null ) ENGINE=MyISAM DEFAULT CHARSET=gbk; insert into test1(field1) values(1); 2¡¢É¾³ýÒÑ´æÔڵĴ洢¹ý³Ì -- ɾ³ý´¢´æ¹ý³Ì delimiter // -- ¶¨Òå½áÊø·ûºÅ drop procedure p_test; 3¡¢mysql´æ´¢¹ý³Ì¶¨
1¡¢Ð½¨±ítest
create table test1(
field1 int not null
)
......
×òÌì½âÎöÁËdblp.xml£¬´æÈëÊý¾Ý¿â£¬Éú³ÉÁËÈô¸ÉÕÅÁÙʱ±í¡£½ñÌìÉÏÎ磬¶ÔÕâЩÁÙʱ±í½øÐд¦Àí£¬È»ºó´æÈëʵÑéÉè¼ÆµÄ±íÖС£Êý¾Ý¿âµÄÊý¾ÝÁ¿±È½Ï´ó£¬50¶àM£¬80¶àÍòÌõ¼Ç¼¡£Òò¶øÖ´ÐÐsqlʱ£¬¾ÍÓöµ½Á˺ܶàÎÊÌâ¡£
1¡¢È¥³ýÖظ´tuple
Ôʼdblp.xmlÖУ¬Í¬Ò»ÂÛÎĵĴæÔÚ¼¸¸öÍêÈ«ÏàͬµÄ&l ......
Ò»¡¢MySQL5.1°²×°
´ò¿ªÏÂÔصݲװÎļþ£¬³öÏÖÈçϽçÃ棺
mysql°²×°Ïòµ¼Æô¶¯£¬µã»÷“next”¼ÌÐø
Ñ¡Ôñ°²×°ÀàÐÍ£¬ÓГTypical£¨Ä¬ÈÏ£©”¡¢“Complete£¨ÍêÈ«£©”¡¢“Custom£¨Óû§×Ô¶ ......
×î½üÒµÎñ·ÃÎÊÁ¿±È½Ï´ó£¬Êý¾Ýͳ¼ÆÀàµÄ²Ù×÷¶¼Çл»µ½mysqlµÄ±¸»úÉÏÈ¥ÁË£¬±¸»úµÄ¶Á²Ù×÷²»»áÓ°ÏìÖ÷¡¢±¸Ö®¼äµÄÈȱ¸µÄ
ÏÂÃæÁÐһϾßÌåµÄÔÀí£º
ÒªÏëÓúÃÒ»¸öϵͳ£¬Àí½âÆäʵÏÖÔÀíÊǷdz£ÖØÒªµÄÊÂÇ飬ֻÓÐÀí½âÁËÆäʵÏÖÔÀí£¬ÎÒÃDzÅÄܹ»Ñﳤ±Ü¶Ì£¬ºÏÀíµÄÀûÓ㬲ÅÄܹ»´î½¨³ö×îÊʺÏÎÒÃÇ×Ô¼ºÓ¦Óû·¾³µÄϵͳ£¬²ÅÄܹ»ÔÚϵͳʵʩ֮ºó¸üºÃµ ......
Mysql³õʼ»¯rootÃÜÂëºÍÔÊÐíÔ¶³Ì·ÃÎÊ
mysqlĬÈÏrootÓû§Ã»ÓÐÃÜÂ룬ÊäÈëmysql –u root ½øÈëmysql
1¡¢³õʼ»¯rootÃÜÂë
½øÈëmysqlÊý¾Ý¿â
1
mysql>update user set password=PASSWORD(‘123456’) where User='root';
2¡¢ÔÊÐímysqlÔ¶³Ì·ÃÎÊ,¿ÉÒÔʹÓÃÒÔÏÂÈýÖÖ·½Ê½:
a¡¢¸Ä±í¡£
1
mysql -u root – ......