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

MySQLÐÔÄÜÓÅ»¯TIPS

Ò». Æô¶¯²ÎÊýÓÅ»¯
ÐÞ¸Ä 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 ¸ö±íÁ¬½Óʱ,Á¬½Ó×ֶεÄÀàÐÍ×îºÃÒ»ÖÂ(°üÀ¨×ֶ㤶È),ÕâÑùµÄ»°Ë÷ÒýËٶȿì¶àÁË.
´ó²¿·ÖÇé¿öÏÂ,×Ö·ûÀàÐ͵Ä×Ö¶ÎË÷ÒýÖµÐèÒªÒ»²¿·Ö,ÀýÈç CREATE INDEX


Ïà¹ØÎĵµ£º

MYSQL¸ß²¢·¢¼Ü¹¹

L1¡¢HTML¾²Ì¬»¯
Æäʵ´ó¼Ò¶¼ÖªµÀ£¬Ð§ÂÊ×î¸ß¡¢ÏûºÄ×îСµÄ¾ÍÊÇ´¿¾²Ì¬»¯µÄhtmlÒ³Ã棬ËùÒÔÎÒÃǾ¡¿ÉÄÜʹÎÒÃǵÄÍøÕ¾ÉϵÄÒ³Ãæ²É Óþ²Ì¬Ò³ÃæÀ´ÊµÏÖ£¬Õâ¸ö×î¼òµ¥µÄ·½·¨ÆäʵҲÊÇ×îÓÐЧµÄ·½·¨¡£µ«ÊǶÔÓÚ´óÁ¿ÄÚÈݲ¢ÇÒƵ·±¸üеÄÍøÕ¾£¬ÎÒÃÇÎÞ·¨È«²¿ÊÖ¶¯È¥°¤¸öʵÏÖ£¬ÓÚÊdzöÏÖÁËÎÒÃdz£¼ûµÄÐÅÏ¢ ·¢²¼ÏµÍ³CMS£¬ÏñÎÒÃdz£·ÃÎʵĸ÷¸öÃÅ»§Õ¾µãµÄÐ ......

mysqlÖ®ÄÚ´æ±í

 ÈçºÎ´´½¨ÄÚ´æ±í
£¿
    ´´½¨ÄÚ´æ±í·Ç³£µÄ¼òµ¥£¬Ö»Ðè×¢Ã÷ ENGINE=
MEMORY ¼´¿É:
    CREATE TABLE  `tablename` ( `columnName` varchar(256) NOT NUL)
ENGINE=MEMORY DEFAULT CHARSET=utf8 MAX_ROWS=100000000;
×¢Òâ
£º
   
µ±ÄÚ´æ±íÖеÄÊý¾Ý´óÓÚmax_ ......

mysqlÓÅ»¯£¨Ðø£©

     ÔÚ¶Ômysql½øÐе÷ÊÔµÄʱºò£¬ÓÉÓÚmysql´æÔÚquery»º´æ£¬³£³£²»ÄÜ·´Ó³ÕæʵÇé¿ö¡£
ÓÐʱºò£¬ÓÐûÓÐʹÓÃFLUSH
QUERY
CACHEµÄȨÏÞ£»
ÔÚ query_cache_type ´ò¿ªµÄÇé¿öÏ£¬Èç¹ûÄã²»ÏëʹÓûº´æ£¬ÐèÒªÖ¸Ã÷
select sql_no_cache id,name from tableName;
»òÕß»¹Óиü¼òµ¥µÄ°ì·¨£¬ÐÞ¸ÄÒ»ÏÂsqlÀïij¸ö×Öĸµ ......

MySQL ×Ö·û´®º¯Êý£º×Ö·û´®½ØÈ¡

 MySQL ×Ö·û´®½ØÈ¡º¯Êý£ºleft(), right(), substring(), substring_index()¡£»¹ÓÐ mid(), substr()¡£ÆäÖУ¬mid(), substr() µÈ¼ÛÓÚ substring() º¯Êý£¬substring() µÄ¹¦Äܷdz£Ç¿´óºÍÁé»î¡£
1. ×Ö·û´®½ØÈ¡£ºleft(str, length)
mysql> select left('sqlstudy.com', 3);
+-------------------------+
| left('sq ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ