mysqlÂý²éѯÈÕÖ¾·ÖÎö
mysql
ÓÐÒ»¸ö¹¦ÄܾÍÊÇ¿ÉÒÔlogÏÂÀ´ÔËÐеıȽÏÂýµÄsqlÓï¾ä£¬Ä¬ÈÏÊÇûÓÐÕâ¸ölogµÄ£¬ÎªÁË¿ªÆôÕâ¸ö¹¦ÄÜ£¬ÒªÐÞ¸Ämy.cnf»òÕßÔÚmysql
Æô¶¯µÄʱºò¼ÓÈëһЩ²ÎÊý¡£
Èç¹ûÔÚmy.cnfÀïÃæÐ޸ģ¬ÐèÔö¼ÓÈçϼ¸ÐÐ
long_query_time = 10
log-slow-queries =
long_query_time
ÊÇÖ¸Ö´Ðг¬¹ý¶à¾ÃµÄsql»á±»logÏÂÀ´£¬ÕâÀïÊÇ10Ãë¡£
log-slow-queries ÉèÖðÑÈÕÖ¾
дÔÚÄÇÀΪ¿ÕµÄʱºò£¬ÏµÍ³»á¸øÂý²éѯ
ÈÕÖ¾¸³ÓèÖ÷»úÃû£¬²¢±»¸½¼Óslow.log
Èç¹ûÉèÖÃÁ˲ÎÊýlog-long-format£¬ÄÇôËùÓÐûÓÐʹÓÃË÷ÒýµÄ²éѯҲ½«±»¼Ç¼¡£ÔÚÎļþmy.cnf»òmy.iniÖмÓÈëÏÂÃæÕâÒ»ÐпÉÒԼǼÕâЩ²éѯ
ÕâÊÇÒ»¸öÓÐÓõÄÈÕÖ¾¡£Ëü¶ÔÓÚÐÔÄܵÄÓ°Ïì²»´ó£¨¼ÙÉèËùÓвéѯ¶¼ºÜ¿ì£©£¬²¢ÇÒÇ¿µ÷ÁËÄÇЩ×îÐèҪעÒâµÄ²éѯ£¨¶ªÊ§ÁËË÷Òý»òË÷ÒýûÓеõ½×î¼ÑÓ¦Óã©
# Time: 070927 8:08:52
# User@Host: root[root] @ [192.168.0.20]
# Query_time: 372 Lock_time: 136 Rows_sent: 152 Rows_examined: 263630
select id, name from manager where id in (66,10135);
ÕâÊÇÂý²éѯ
ÈÕÖ¾ÖеÄÒ»Ìõ£¬ÓÃÁË372Ã룬ËøÁË136Ã룬·µ»Ø152ÐУ¬Ò»¹²²éÁË263630ÐÐ
Èç¹ûÈÕÖ¾ÄÚÈݺܶ࣬ÓÃÑÛ¾¦Ò»ÌõÒ»ÌõÈ¥¿´»áÀÛËÀ£¬mysql
×Ô´øÁË·ÖÎöµÄ¹¤¾ß£¬Ê¹Ó÷½·¨ÈçÏ£º
ÃüÁîÐÐÏ£¬½øÈëmysql
/bin
Ŀ¼£¬ÊäÈëmysqldumpslow –help
»ò--help
¿ÉÒÔ¿´µ½Õâ¸ö¹¤¾ßµÄ²ÎÊý£¬Ö÷ÒªÓÐ
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL
slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (t, at, l, al, r, ar etc), 'at' is default
-r reverse the sort order (largest last instead of first)
-t NUM just show the to
Ïà¹ØÎĵµ£º
Ò»¡¢Á¬½ÓMYSQL
¸ñʽ£º mysql -hÖ÷»úµØÖ· -uÓû§Ãû -pÓû§ÃÜÂë
1¡¢ÈôÊÇÁ¬½Óµ½±¾»úÉϵÄMYSQL£ºÊ×ÏÈ´ò¿ªDOS´°¿Ú£¬È»ºó½øÈëĿ¼mysql\bin£¬»òÕß½«mysql\bin°²×°Â·¾¶ÉèÖÃÔÚ»·¾³±äÁ¿pathÖУ¬ÔÙ¼üÈëÃüÁîmysql -u root -p£¬»Ø³µºóÌáʾÄãÊäÃÜÂë.×¢ÒâÓû§ÃûÇ°¿ÉÒÔÓпոñÒ²¿ÉÒÔûÓпոñ£¬µ«ÊÇÃÜÂëÇ°± ......
ÔÚmysqlµÄslow query logÖУ¬¿ÉÄÜ´æÔÚÀàËÆÕâÑùµÄÌØÊâ¼Ç¼£º
# Time: 100127 23:17:01
# User@Host: root[root] @ [127.0.0.1]
# Query_time: 18446744073709.351562 Lock_time: 0.000129 Rows_sent: 1 Rows_examined: 11030
SET timestamp=1264663021;
SELECT dummy.id AS dummy_id
from dummy&nbs ......
MYSQL where id inÎÊÌâ
SELECT * from product WHERE id IN (‘1522,1523,1524′)ORDER BY id DESC
ÔÚMYSQLÀïÃæÖ´ÐÐÕâ¸öÓï¾äÖ»·µ»Ø1522µÄÖµ¡£
Ö´ÐÐ
SELECT * from product WHERE instr(‘1522,1523,1524′,id) ORDER BY id DESC
»òÕß
SELECT * from product WHERE instr(‘1522,1523,1524 ......
ÎÒµÄϵͳÊÇredhat as5 ½¨Òé´ó¼ÒÍêÈ«°²×°£¬ÒÔÃⰲװʱȱÉÙÏà¹ØµÄ±àÒëÆ÷µÈµÈ¡£
Ò»¡¢°²×°mysql£¨mysql-5.0.21.tar.gz£©
# tar zxf mysql-5.0.21.tar.gz
# cd mysql-5.0.21
#./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql/
˵Ã÷£º
#prefix=/usr/lo ......