MySQLµÄ±íËøÎÊÌâ
ÔÚmysqlÊÖ²áÀïÃæÓÐÒ»¶ÎÃèÊö¹ØÓÚlock tablesµÄÓï·¨µÄ.
LOCK TABLES tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE} [, tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}] ...UNLOCK TABLESREAD
µ±±í²»´æÔÚ WRITE дËøʱ READ ¶ÁËø±»Ö´ÐÐ,Õâ¸Ã״̬ÏÂ,µ±Ç°Ï̲߳»¿ÉÒÔÐÞ¸Ä(insert,update,delete),ÆäËûÏ̵߳ÄÐ޸IJÙ×÷½øÈëÁжÓ,µ±µ±Ç°Ïß³ÌÊÍ·ÅËø,ÆäËûÏß³ÌÐ޸ı»Ö´ÐÐ.
READ LOCAL
READ LOCALºÍREADÖ®¼äµÄÇø±ðÊÇ£¬READ LOCALÔÊÐíÔÚËø¶¨±»±£³Öʱ£¬Ö´ÐзdzåÍ»ÐÔINSERTÓï¾ä£¨Í¬Ê±²åÈë-Concurrent InsertµÄÌØÐÔ£¬Ö÷ÒªÊÇÕë¶ÔMyISAM´æ´¢ÒýÇæÀ´ËµµÄ£©¡£µ«ÊÇ£¬Èç¹ûÄúÕý´òËãÔÚMySQLÍâÃæ²Ù×÷Êý¾Ý¿âÎļþ£¬Í¬Ê±Äú±£³ÖËø¶¨£¬Ôò²»ÄÜʹÓÃREAD LOCAL¡£¶ÔÓÚInnoDB±í£¬READ LOCALÓëREADÏàͬ(tenfyµÄʵÑé½áÂÛÊÇ£ºMyISAM´æ´¢ÒýÇ棬ȷʵÔÚÏß³ÌaÖ´ÐÐread local rockºó£¬ÆäËûÏß³ÌÊÇ¿ÉÒÔÔÙ½øÐÐinsert²Ù×÷µÄ£¬updateÔò±»×èÈû£¬µ«¶ÔInnoDB´æ´¢ÒýÇæÀ´Ëµ£¬insertºÍupdate¾ù±»×èÈû£¬Òò´Ëread local¸ü¶àµÄÊǶÔMyISAM´æ´¢ÒýÇæÀ´ËµµÄ)¡£
WRITE
³ýÁ˵±Ç°Óû§±»ÔÊÐí¶ÁÈ¡ºÍÐ޸ı»Ëø±íÍ⣬ÆäËûÓû§µÄËùÓзÃÎʱ»ÍêÈ«×èÖ¹¡£×¢ÒâµÄÊÇÔÚµ±Ç°Ï̵߳±WRITE±»Ö´ÐеÄʱºò,¼´Ê¹Ö®Ç°¼ÓÁËREADû±»È¡Ïû,Ò²»á±»È¡Ïû.
LOW_PRIORITY WRITE
½µµÍÓÅÏȼ¶µÄWRITE,ĬÈÏWRITEµÄÓÅÏȼ¶¸ßÓÚREAD.¼ÙÈ統ǰÏ̵߳ÄLOW_PRIORITY WRITEÔÚÁжÓÀïÃæ,ÔÚδִÐÐ֮ǰÆäËûÏ̴߳«ËÍÒ»ÌõREAD,ÄÇôLOW_PRIORITY WRITE¼ÌÐøµÈ´ý.
µ±ÄúʹÓÃLOCK TABLESʱ£¬Äú±ØÐëËø¶¨Äú´òËãÔÚ²éѯÖÐʹÓõÄËùÓÐµÄ±í¡£ËäȻʹÓÃLOCK TABLESÓï¾ä»ñµÃµÄËø¶¨ÈÔÈ»ÓÐЧ£¬µ«ÊÇÄú²»ÄÜ·ÃÎÊûÓб»´ËÓï¾äËø¶¨µÄÈÎºÎµÄ±í¡£Í¬Ê±£¬Äú²»ÄÜÔÚÒ»´Î²éѯÖжà´ÎʹÓÃÒ»¸öÒÑËø¶¨µÄ±í——ʹÓñðÃû´úÌ棬ÔÚ´ËÇé¿öÏ£¬Äú±ØÐë·Ö±ð»ñµÃ¶Ôÿ¸ö±ðÃûµÄËø¶¨¡£
ÊÖ²á¸ø³öÁËÈçϵÄÀý×Ó:
mysql> LOCK TABLE t WRITE, t AS t1 WRITE;#´ËʱËø¶¨µÄÓ¦¸ÃËãÊÇt±íºÍËüµÄ±ðÃût1
mysql> INSERT INTO t SELECT * from t;#´ËʱʹÓÃÁË2´Ît±í
ERROR 1100: Table 't' was not locked with LOCK TABLES
mysql> INSERT INTO t SELECT * from t AS t1;
Èç¹ûÄúµÄ²éѯʹÓÃÒ»¸ö±ðÃûÒýÓÃÒ»¸ö±í£¬ÄÇôÄú±ØÐëʹÓÃͬÑùµÄ±ðÃûËø¶¨¸Ã±í¡£Èç¹ûûÓÐÖ¸¶¨±ðÃû£¬Ôò²»»áËø¶¨¸Ã±í¡£
mysql> LOCK TABLE t READ;
mysql> SELECT * from t AS myalias;#ÒòΪ²»ÄÜ·ÃÎÊûÓб»Óï¾äËø¶¨µÄÈκεıí,Ó¦¸ÃËã°É±ðÃûmyaliasËã×÷±íÁË
ERROR 1
Ïà¹ØÎĵµ£º
ÊýÖµÀàÐÍ
¡¡¡¡MySQL
µÄÊýÖµÊý¾ÝÀàÐÍ¿ÉÒÔ´óÖ»®·ÖΪÁ½¸öÀà±ð£¬Ò»¸öÊÇÕûÊý£¬ÁíÒ»¸öÊǸ¡µãÊý»òСÊý¡£Ðí¶à²»Í¬µÄ×ÓÀàÐͶÔÕâЩÀà±ðÖеÄÿһ¸ö¶¼ÊÇ¿ÉÓõģ¬Ã¿¸ö×ÓÀàÐÍÖ§³Ö²»Í¬´óСµÄÊý¾Ý£¬²¢ÇÒ
MySQL ÔÊÐíÎÒÃÇÖ¸¶¨ÊýÖµ×Ö¶ÎÖеÄÖµÊÇ·ñÓÐÕý¸ºÖ®·Ö»òÕßÓÃÁãÌî²¹¡£
¡¡¡¡±íÁгöÁ˸÷ÖÖÊýÖµÀàÐÍÒÔ¼°ËüÃǵÄÔÊÐí·¶Î§ºÍÕ¼ÓõÄÄÚ´æ¿Õ¼ä¡ ......
³õѧphp,ÐèÒª´î½¨Æ俪·¢»·¾³¡£ÓÉÓÚ°æ±¾¸üÌæµÈÔÒò£¬ÍøÉϵķ½·¨¼¸ºõÒ»ÈËÒ»¸öÑù£¬ÈÃÈËÎÞËùÊÊ´Ó¡£×òÌ컨ÁËÒ»ÍíÉÏʱ¼ä²ÅÔÚXPÏÂÅäÖúã¬ÏÖ½«ÆäÕûÀí³öÀ´£¬Ï£ÍûÄܶԱðÈËÓÐÓᣣ¨2007-11-21£©
Ò»¡¢ ÏÂÔØÈí¼þ¡£
1. ÏÂÔØapache_2.0.55-win32-x86-no_ssl.msi£¬ÓÒ¼üÓÃѸÀ×µã»÷´Ë´¦ÏÂÔØ£¨Ö±½Óµã»÷²»ÐУ©¡£
2. ÏÂÔØphp-5 ......
½â¾öÂÒÂë×îºÃµÄ·½·¨ÊÇÔÚÏîÄ¿Éè¼ÆÖ®³õ£¬Í³Ò»ËùÓеÄ×Ö·û¼¯£¬ÀýÈçÒ³Ãæ¡¢request¶ÔÏóÒÔ¼°Êý¾Ý¿âµÈµÈ¡£
Ò»¡¢
¼¸ÖÖ³£¼ûµÄÂÒÂëÏÖÏó£º
1¡¢Ò³ÃæÂÒÂë
µ¥´¿µÄÒ³ÃæÂÒÂëÊǺܺýâ¾öµÄ£¬Ö»ÒªÐÞ¸ÄÍ·²¿ÊʺϵÄ×Ö·û¼¯¼´¿É£¬Èç¹ûÒ³ÃæÖÐÎÄÏÔʾÂÒÂ룬Äã¿ÉÒÔ°Ñ×Ö·û¼¯ÐÞ¸ÄΪ£ºgb2312»ògbk¡£
2¡¢
Ò³ÃæÖ®¼ä´«µÝµÄ²Î ......
Èç¹ûÄãÊǸöÈü³µÊÖ£¬²¢ÇÒ°´Ò»Ï°´Å¥¾ÍÄܹ»Á¢¼´¸ü»»ÒýÇæ¶ø²»ÐèÒª°Ñ³µ¿ªµ½³µ¿âÀïÈ¥»»£¬ÄÇ»áÊÇʲô¸Ð¾õÄØ£¿MySQLÊý¾Ý¿âΪ¿ª·¢ÈËÔ±Ëù×öµÄ¾ÍºÃÏñÊÇ°´°´Å¥»»ÒýÇ棻ËüÈÃÄãÑ¡ÔñÊý¾Ý¿âÒýÇ棬²¢¸øÄãÒ»Ìõ¼òµ¥µÄ;¾¶À´Çл»Ëü¡£
MySQLµÄ×Ô´øÒýÇæ¿Ï¶¨Êǹ»ÓÃÁË£¬µ«ÊÇÔÚÓÐЩÇé¿öÏ£¬ÆäËûµÄÒýÇæ¿ÉÄÜÒª±ÈÊÖÍ·ËùÓøüÊʺÏÍê³ÉÈÎÎñ¡£Èç¹ûÔ¸ ......