×ܽáÁËһЩMySQLÓÅ»¯·½ÃæµÄ¼¼ÇÉ
Ò». Æô¶¯²ÎÊýÓÅ»¯
ÐÞ¸Ä my.cnf (»òÕßmy.ini)£¬¼ÓÈë/ÐÞ¸ÄÒÔϼ¸ÐÐ
#É趨»º´æµÄÁ¬½ÓÊý,½ÚÊ¡Á¬½ÓʱµÄ¿ªÏú
back_log = 64
#½ûÓÃÎļþϵͳÍⲿËø
external-locking = 0
#½ûÓÃBDB,Èç¹ûÄãȷʵ²»ÐèÒªµÄ»°,innodbÒ²ÊÇÈç´Ë
skip-bdb
#Ë÷Òý»º³å,Èç¹ûÊÇרÓõÄÊý¾Ý¿â·þÎñÆ÷,¿ÉÒÔÉèÖøߴï·þÎñÆ÷ÄÚ´æµÄÒ»°ë,Èç¹û²»ÊÇרÓõÄ,
#»¹ÊÇÉèÖõõÍÒ»µã
key_buffer = 512M
#»º´æÊý¾Ý±íÊýÁ¿,Èç¹ûÄÚ´æ½Ï´ó,¿ÉÒÔÉèÖÃÉÔ΢¸ßÒ»µã,·ñÔò»¹ÊÇÉèÖõÍÒ»µã
#ÉèÖÃÕâ¸ö²ÎÊý¿ÉÒԲμûϵͳ״̬ÖÐµÄ open_tables(±íʾµ±Ç°´ò¿ªµÄÊý¾Ý±í×ÜÊý)
#ºÍ opened_tables(±íʾËùÓдò¿ªµÄÊý¾Ý±í×ÜÊý)
table_cache = 128
#½ûÓÃdns½âÎö,Èç¹ûÄãµÄÊÚȨÐÅÏ¢ÖвÉÓÃdnsÊÚȨ·½Ê½ÁË,¾Í²»ÄÜÆôÓøÃÑ¡Ïî
skip-name-resolve
#¼Ç¼Âý²éѯºÍûÓÐʹÓÃË÷ÒýµÄ²éѯ,±ãÓÚ°ïÖú·ÖÎöÎÊÌâËùÔÚ
long_query_time = 1
log-slow-queries = /usr/local/mysql/data/slow.log
log-queries-not-using-indexes
ÆäËû²ÎÊýÖîÈç sort_buffer_size,net_buffer_length,read_buffer_size,read_rnd_buffer_size,myisam_sort_buffer_size,
thread_cache_size,query_cache_size,max_binlog_cache_size µÈÇë²éѯMySQLÊÖ²á,È»ºó×ö³öºÏÊʵĵ÷Õû.
¶þ. ÆäËûСTIPS
* Õë¶ÔInnodb±í,¾¡Á¿²»Ö´ÐÐ SELECT COUNT(*) Óï¾ä,ÒòΪInnodb±íûÓÐÀàËÆMyISAMÄÇÑùµÄÄÚ²¿¼ÆÊýÆ÷À´¼Ç¼±í¼Ç¼×ÜÁ¿,Ö´ÐÐÕâ¸ö²Ù×÷½«»áÈ«±íɨÃè,ËٶȺÜÂý.
* ¾¡Á¿Ê¹ÓÃMyISAM±í,³ý·Ç±ØÐëʹÓÃÆäËûÀàÐÍ,ÒòΪMyISAMÀàÐ͵Ä×ÜÌå¶ÁдЧÂÊÊÇÏ൱¸ßµÄ,ȱµãÊÇ±í¼¶Ëø,¶ø²»ÊÇÐÐ/Ò³¼¶Ëø.
* ÉÆÓà EXPLAINÀ´°ïÖúÄã·ÖÎö²éѯÓÅ»¯Çé¿ö
* Èç¹ûÐèÒª¶ÔÒ»¸ö½Ï´óµÄÇÒ²¢·¢¶Áд½Ï¶àµÄÊý¾Ý±í×ö GROUP BY µÈͳ¼Æ²Ù×÷,½¨ÒéʹÓÃÕªÒª±íÀ´´æ´¢Í³¼ÆÐÅÏ¢,¶¨ÆÚ¸üÐÂͳ¼Æ±í,Õâ¿ÉÄÜ»ñµÃºÜ´óµÄÐÔÄܸÄÉÆ.
* ²éѯʱÈç¹ûÓÐ ORDER BY·Ö¾äµÄ»°,×¢ÒâÈÃËüµÄ×Ö¶Î˳ÐòºÍË÷Òý×Ö¶Î˳Ðò¶ÔÓ¦,ÕâÑùÄܼӿìÅÅÐòËÙ¶È
* Èç¹ûÓÐÒ»¸ö¶à×Ö¶ÎË÷Òý,Ôò²éѯʱ,±ØÐë°´ÕÕË÷Òý˳ÐòÀ´Ê¹ÓÃ,·ñÔò¸ÃË÷Òý²»»áÓõ½.ÀýÈç:
Ë÷Òý `idx_`(col1, col2, col3),ÄÇô²éѯ SELECT .... from ... WHERE col1=1 AND col2=2; ʹÓÃË÷Òý,¶ø²éѯ ... WHERE col2=2 AND col3=3; »ò ... WHERE col1=1 AND col3=3; Ôò²»Ê¹ÓÃË÷Òý.
* WHERE ÖеÄÌõ¼þÈç¹ûÓкãÁ¿ÀàÐ͵Ä(Èç `field` = 1),¾Í¾¡Á¿·ÅÔÚÇ°Ãæ,ÕâÑùÄܸü¿ìµÄÖ´ÐйýÂË.
* 2 ¸ö±íÁ¬½Óʱ,Á¬½Ó×ֶεÄÀàÐÍ×îºÃÒ»ÖÂ(°üÀ¨×ֶ㤶È),ÕâÑùµÄ»°Ë÷ÒýËٶȿì¶àÁË.
* ´ó²¿·ÖÇé¿öÏÂ,×Ö·ûÀàÐ͵