Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

mySqlÖÐÈçºÎÅúÁ¿¸üмÆÊýÆ÷


¼ÙÈçÎÒÃǵÄmysqlÓÐÒ»¸ö¼ÆÊýÆ÷£¬¶øÕâ¸ö¼ÆÊýÆ÷ÐèÒªÎÒÃÇÖØÐÂͳ¼Æ£¬Ôõô°ìÄØ£¿
Ó¦Óó¡¾°£¬±ÈÈç˵ÓÐÒ»¸öÉ̳¡£¬Ã¿ÂôÒ»¸ö²úÆ·¶¼²úÉúÒ»¸öÁ÷Ë®£¬È»ºóÎÒÃÇÐèÒªÖªµÀÿ±ÊÁ÷Ë®ÊǸòúÆ·µÚ¼¸´Î³öÊ۵ģ¬ÕâÑù˵¿ÉÄܲ»Ã÷°×£¬ÎÒÄÃÒ»¸öÏêϸµÄÊý¾Ý
¾ÙÀý°É¡£
recordID,productID,productType,sellDate,counter
1, 1, 1, '2010-1-15 15:20:10' 0
2, 1, 2, '2010-1-15 15:20:10' 1
3, 2, 1, '2010-1-15 15:20:10' 0
4, 2, 1, '2010-1-15 15:20:10' 1
ÉÏÃæÕâ¸öÊý¾ÝÊÇһЩÈöÆøÊý¾Ý£¬°üÀ¨¼Ç¼µÄÁ÷Ë®ºÅ£¬²úÆ·µÄ±àºÅ£¬²úÆ·µÄÀàÐÍ£¬ÏúÊÛµÄʱ¼ä£¬¼ÆÊýÆ÷¡£Ò»°ãÀ´Ëµ£¬¼ÆÊýÆ÷ÎÒÃÇÊ×ÏÈÎÒ»áÏëµ½×ÔÔö£¬µ«Õâ¶ø¿Ï¶¨
ÊDz»¿ÉÄÜʹÓÃ×ÔÔö³¤µÄ¡£
ÎÒ×î³õµÄʱºò£¬³¢Ê¹ÓÃÕâÑùµÄ´úÂ룺update t_product set t_counter = (select max(counter)
from t_product where productid = 1 and productType = 1) + 1 where where
productid = 1 and productType = 1
µ«ÊÇmysql±¨´í£¬ÉÏÍøÒ»²é£¬mysql²»Ö§³ÖÕâÖÖд·¨£¬ºÇºÇ£¬ÎÒ¶ÔmysqlÍêÈ«²»ÊìϤ¡£¼ÇµÃÒÔÇ°ÔÚsql
serverÓùýÓα꣬ȻºóÒ²ÊÔÊÔ²éÕÒÓα꣬¾­¹ýn´ÎgoogleÓë°Ù¶È£¬×îÖո㶨Õâ¸öÄÑÌâ¡£
ÎÒ±¾Éí¶ÔmysqlÍêÈ«ÊǸöÍâÐУ¬¾ÍÁ¬×¢ÊÍÒ²²»ÖªµÀÔõôעÊ͵ģ¬ÏÖÔÚÖÕÓÚÖªµÀÓÐÈýÖÖд·¨µÄ£¬¶ø--µÄ×¢ÊͺóÃæÊÇÒª¿ÕÒ»¸ñµÄ£¬ËùÒÔ´úÂëдµÃÐÔÄÜʲôµÄ
¾Í²»¸Ò˵ÁË£¬Ö»ÊÇʵÏÖÁËÕâ¸ö¹¦ÄÜ£¬Ï£Íû¶ÔÓÐͬÑùÐèÇóµÄÅóÓÑÓÐÓá£
ºÇ£¬»¹Ñ§µ½Ò»µã£¬declareÖ»ÄÜдÔÚ×îÇ°Ãæ¡£
¿´×îÖյĴúÂ룺
CREATE
PROCEDURE
p_resetCounter (
)
BEGIN
DECLARE
productID INT
;
DECLARE
type
INT
;
DECLARE
tmpCount INT
;
DECLARE
stopFlag int
;
 
#ʹÓÃÓαê
DECLARE
cur cursor for SELECT
COUNT
(
*
)
,
productID,
productType from
t_product GROUP BY
productID,
productType;
DECLARE
CONTINUE HANDLER
FOR NOT
FOUND set
stopFlag=
1
;
#Èç¹ûÕÒ²»µ½¼Ç¼£¬ÔòÉèÖÃstopFlag=1
 
#¶¨Òå±äÁ¿¼°´´½¨ÁÙʱ±í
CREATE
TEMPORARY
TABLE
tmp_Counter(
recordID int
not
null
,
Counter int
not
null
)
TYPE
=
HEAP;
 
#´ò¿ªÓαê
open cur;
REPEAT
fetch cur into
tmpCount,
productID,
type
;
SET
@id =
-
1
;
INSERT
INTO
tmp_Counter
(
SELECT
recordID,
(
@id :=
@id +
1
)
counter
from
t_prod


Ïà¹ØÎĵµ£º

²»ÒªÊ¹ÓÃһЩmysqlÌØÓеÄtipÀ´Ð´²éѯ

http://immike.net/blog/2007/04/09/how-not-to-optimize-a-mysql-query/
ÕâƪÎÄÕ½¨Ò飺
£¨1£©²»ÒªÊ¹ÓÃһЩmysqlµÄtip£¬È磺SQL_SMALL_RESULT, HIGH/LOW_PRIORITY, and INSERT DELAYED£¬STRAIGHT_JOIN£¬³ý·ÇûÓÐÆäËû·½·¨£¬ÒòΪÕâÑùʧȥÁËSQLµÄ¿ÉÒÆÖ²ÐÔ
£¨2£©Êʵ±¶Ô±í½øÐÐË÷Òý
£¨3£©±ÜÃâ¶Ô²»±ØÒªÊý¾ÝµÄ²éѯ
£¨4£©´¦Àí× ......

mysql archive´æ´¢ÒýÇæ

http://www.mysqlperformanceblog.com/2006/11/12/trying-archive-storage-engine/
£¨1£©ÔÚÏàͬµÄÌõ¼þÏ£¬archiveµÄÊý¾Ý´óСԶСÓÚmyisam
£¨2£©ÔÚѹËõarchiveÊý¾Ýʱ£¬bzip2ºÃÓÚgzip
£¨3£©ÐèÒªÌí¼ÓarchiveµÄ·½·¨ºÍѹËõµÄlevel£¬ÒÔÂú×㲻ͬÓû§µÄÐèÇó
£¨4£©Õâ¸ö´æ´¢ÒýÇæÊÊÓÃÓÚÈÕÖ¾Êý¾Ý
£¨5£©´ËÒýÇæ²»ÄÜupdate,delete£¬²¢ ......

MySQL5.1ÄÚ±íתµ½MS SQL£¬±í½á¹¹Ó¦ÈçºÎÉèÖã¿

# MySQL-Front 5.1  (Build 4.2)
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40103 SET SQL_NOTES='ON' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS */ ......

mysqlÂÒÂëÎÊÌâ½â¾ö·½°¸

1.       °²×°mysqlµÄʱºòÑ¡Ôñ×Ö·û¼¯utf8
2.       °²×°½áÊøºóÐÞ¸Ämy.ini,ÓÐÁ½¸öµØ·½ÒªÐ޸ģ¬
[mysql] default-character-set=gbk
 
# The default character set that will be used when a new schema or table is
# created and no character set ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ