mysql ÌáÉýÃüÖÐÂÊ
Query Cache ÔÚÌá¸ßÊý¾Ý¿âÐÔÄÜ·½Ãæ¾ßÓзdz£ÖØÒªµÄ×÷Óá£
ÆäÉ趨Ҳ·Ç³£¼òµ¥£¬½öÐèÒªÔÚÅäÖÃÎļþдÈëÁ½ÐУº query_cache_type ºÍ query_cache _size£¬¶øÇÒ MySQL µÄ query cache ·Ç³£¿ì£¡¶øÇÒÒ»µ©ÃüÖУ¬¾ÍÖ±½Ó·¢Ë͸ø¿Í»§¶Ë£¬½ÚÔ¼´óÁ¿µÄ CPU ʱ¼ä¡£
µ±È»£¬·Ç SELECT Óï¾ä¶Ô»º³åÊÇÓÐÓ°ÏìµÄ£¬ËüÃÇ¿ÉÄÜʹ»º³åÖеÄÊý¾Ý¹ýÆÚ¡£Ò»¸ö UPDATE Óï¾äÒýÆðµÄ²¿·Ö±íÐ޸ģ¬½«µ¼Ö¶ԸñíËùÓеĻº³åÊý¾ÝʧЧ£¬ÕâÊÇ MySQL ΪÁËƽºâÐÔÄܶøûÓвÉÈ¡µÄ´ëÊ©¡£ÒòΪ£¬Èç¹ûÿ´Î UPDATE ÐèÒª¼ì²éÐ޸ĵÄÊý¾Ý£¬È»ºó³·³ö²¿·Ö»º³å½«µ¼Ö´úÂëµÄ¸´ÔÓ¶ÈÔö¼Ó¡£
query_cache_type 0 ´ú±í²»Ê¹Óûº³å£¬ 1 ´ú±íʹÓûº³å£¬2 ´ú±í¸ù¾ÝÐèҪʹÓá£
ÉèÖà 1 ´ú±í»º³åÓÀÔ¶ÓÐЧ£¬Èç¹û²»ÐèÒª»º³å£¬¾ÍÐèҪʹÓÃÈçÏÂÓï¾ä£º
SELECT SQL_NO_CACHE * from my_table WHERE ...
Èç¹ûÉèÖÃΪ 2 £¬ÐèÒª¿ªÆô»º³å£¬¿ÉÒÔÓÃÈçÏÂÓï¾ä£º
SELECT SQL_CACHE * from my_table WHERE ...
Óà SHOW STATUS ¿ÉÒԲ鿴»º³åµÄÇé¿ö£º
mysql> show status like 'Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_queries_in_cache | 8 |
| Qcache_inserts | 545875 |
| Qcache_hits | 83951 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 2343256 |
| Qcache_free_memory | 33508248 |
| Qcache_free_blocks | 1 |
| Qcache_total_blocks | 18 |
+-------------------------+----------+
8 rows in set (0.00 sec)
Èç¹ûÐèÒª¼ÆËãÃüÖÐÂÊ£¬ÐèÒªÖªµÀ·þÎñÆ÷Ö´ÐÐÁ˶àÉÙ SELECT Óï¾ä£º
mysql> show status like 'Com_sel%';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Com_select | 2889628 |
+---------------+---------+
1 row in set (0.01 sec)
ÔÚ±¾ÀýÖУ¬ MySQL ÃüÖÐÁË 2,889,628 Ìõ²éѯÖÐµÄ 83,951 Ìõ£¬¶øÇÒ INSERT Óï¾äÖ»ÓÐ 545,875 Ìõ¡£Òò´Ë£¬ËüÃÇÁ½ÕߵĺͺÍ280ÍòµÄ×ܲéѯÏà±ÈÓкܴó²î¾à£¬Òò´Ë£¬ÎÒÃÇÖªµÀ±¾ÀýʹÓõĻº³åÀàÐÍÊÇ 2 ¡£
¶øÔÚÀàÐÍÊÇ 1 µÄÀý×ÓÖУ¬ Qcache_hits µÄÊýÖµ»áÔ¶Ô¶´óÓÚ Com_select ¡£
Ïà¹ØÎĵµ£º
Õª×Ôhttp://blog.csdn.net/ljah/archive/2006/11/08/1373959.aspx
¸ñʽ£º
CREATE PROCEDURE ¹ý³ÌÃû ([¹ý³Ì²ÎÊý[,...]])
[ÌØÐÔ ...] ¹ý³ÌÌå
CREATE FUNCTION º¯ÊýÃû ([º¯Êý²ÎÊý[,...]])
RETURNS ·µ»ØÀàÐÍ
[ÌØÐÔ ...] º¯ÊýÌå
¹ý³Ì²ÎÊý:
[ IN | OUT | INOUT ] ²ÎÊýÃû ²ÎÊýÀàÐÍ
º¯Êý²ÎÊý:
²ÎÊýÃû ²ÎÊýÀàÐÍ
·µ»ØÀàÐÍ: ......
mysqlÔÚsdkÖÐΪcÓïÑÔÌṩÁËһЩ·ÃÎʽӿڣ¬ÎÒÃÇ¿ÉÒÔʹÓÃÕâЩ½Ó¿ÚÁ¬½Ó²¢·ÃÎÊmysqlÊý¾Ý¿â£¬µ±È»Ò²¿ÉÒÔµ÷ÓÃmysqlµÄ´æ´¢¹ý³Ì¡£
Àý×Ó£º
Ê×ÏÈÏÂÔØmysqlµÄsdk£¬½âѹºÃÒÔºó£¬ÀïÃæ°üº¬Ò»¸öinclude,ºÍlibÎļþ¼Ð¡£ÎÒÃÇÔÚ×Ô¼ºµÄ¹¤³ÌÖаüº¬ÕâÁ½¸öÎļþ¼ÐµÄĿ¼£¬²¢Ç ......
²âÊÔ»·¾³£ºUbuntu 9.10 + MySQL 5.1.37-1ubuntu5
Ubuntu ÔÚÆô¶¯¹ÜÀí init.d
ÀïÃæ¹ØÓÚ MySQL µÄÃüÁîÓУº
/etc/init.d/mysql start|stop|restart|reload|force-reload|status
ÀýÈçÖØÆôMySQL·þÎñ£ºsudo /etc/init.d/mysql restart
......
Êý¾Ý¿âµÄÓÅ»¯ÊÇϵͳÓÅ»¯µÄÖØÒª·½Ã棬¶øÊý¾Ý¿âÓÅ»¯µÄ»ù´¡ÊÇ»ùÓÚͳ¼ÆÊý¾Ý£¬ÏÂÃæµÄÕâЩÃüÁî¿ÉÒÔ°ïÖúÎÒÃÇÁ˽âÊý¾Ý¿âµÄ״̬¡£±ÈÈçÓÃshow table status from ecl where rows>10000;¿ÉÒÔ¿´ÄÄЩÊý¾Ý¿â±í±È½Ï´ó£¬È»ºó¿´¿´ÕâЩ±íµÄÉèÖá¢Ë÷ÒýµÈÊÇ·ñÓÐÎÊÌâ¡£
1. show tables»òshow tables from dat ......
truncate table Çå¿Õ±í£¬ºÍdeleteÏàËÆ£¬µ«ÊÇÔÚ±í·Ç³£´óµÄʱºò£¬ËüÊÇÖð²½Êͷŵġ£
insert Èç¹ûÔÚ²åÈëʱ£¬Ä³¸ö×ֶδæÔÚ£¬ÎÒÏë¸üпÉÒÔͨ¹ý insert into tablename values() on duplicate key update id=id+1;
insert into tablename values(default) ĬÈÏ×ÔÔö³¤
select last_insert_id() È¡×îºó²åÈëÒ»Ìõ¡£ ......