ÒªÓÅ»¯ÅäÖòÎÊý£¬Ê×ÏÈÒªÁ˽⵱ǰµÄÅäÖòÎÊýÒÔ¼°ÔËÐÐÇé¿ö¡£Ê¹ÓÃÏÂÁÐÃüÁî¿ÉÒÔ»ñµÃÄ¿Ç°·þÎñÆ÷ʹÓõÄÅäÖòÎÊý£º
mysqld -verbose -help
mysqladmin variables extended-status -u root -p
ÔÚMySQL ¿ØÖÆ̨ÀïÃ棬ÔËÐÐÏÂÁÐÃüÁî¿ÉÒÔ»ñȡ״̬±äÁ¿µÄÖµ£º
mysql> SHOW STATUS;
Èç¹ûÖ»Òª¼ì²éij¼¸¸ö״̬±äÁ¿£¬¿ÉÒÔʹÓÃÏÂÁÐÃüÁ
mysql> SHOW STATUS LIKE ¡®[ Æ¥Åäģʽ]¡¯; ( ¿ÉÒÔʹÓÃ% ¡¢? µÈ )
2£®ÓÅ»¯²ÎÊý
²ÎÊýÓÅ»¯»ùÓÚÒ»¸öÇ°Ìᣬ¾ÍÊÇÔÚÎÒÃǵÄÊý¾Ý¿âÖÐͨ³£¶¼Ê¹Óà InnoDB±í£¬¶ø²»Ê¹Óà MyISAM±í¡£ ÔÚÓÅ»¯MySQLʱ£¬ÓÐÁ½¸öÅäÖòÎÊýÊÇ×îÖØÒªµÄ£¬¼´ table_cacheºÍ key_buffer_size¡£
table_cache
table_cache Ö¸¶¨±í¸ßËÙ»º´æµÄ´óС¡£Ã¿µ±MySQL·ÃÎÊÒ»¸ö±íʱ£¬Èç¹ûÔÚ±í»º³åÇøÖл¹Óпռ䣬¸Ã±í¾Í±»´ò¿ª²¢·ÅÈëÆäÖУ¬ÕâÑù¿ÉÒÔ¸ü¿ìµØ·ÃÎʱíÄÚÈÝ¡£Í¨¹ý¼ì²é·åֵʱ¼äµÄ״ֵ̬ Open_tablesºÍ Opened_tables£¬¿ÉÒÔ¾ö¶¨ÊÇ·ñÐèÒªÔö¼Ó table_cacheµÄÖµ¡£Èç¹ûÄã·¢ÏÖ open_tablesµÈÓÚ table_cache£¬²¢ÇÒ opened_tablesÔÚ²»¶ÏÔö³¤£¬ÄÇôÄã¾ÍÐèÒªÔö¼Ó table_cacheµÄÖµÁË£¨ÉÏÊö״ֵ̬¿ÉÒÔʹÓÃSHOW STATUS LIKE ¡®Open%tables¡¯»ñµÃ£©¡£×¢Òâ £¬²»ÄÜäĿµØ°Ñ table_cacheÉèÖóɺܴóµÄÖµ¡£Èç¹ûÉèÖõÃÌ«¸ß£¬¿ÉÄÜ»áÔì³ÉÎļþÃèÊö·û²»×㣬´Ó¶øÔì³ÉÐÔÄܲ»Îȶ¨»òÕßÁ¬½Óʧ°Ü¡£
¶ÔÓÚÓÐ1G ÄÚ´æµÄ»úÆ÷£¬ÍƼöÖµÊÇ128 £256 ¡£
°¸Àý1£º¸Ã°¸ÀýÀ´×ÔÒ»¸ö²»ÊÇÌرð·±Ã¦µÄ·þÎñÆ÷
table_cache - 512
open_tables - 103
opened_tables - 1273
uptime - 4021421 (measured in seconds)
¸Ã°¸ÀýÖÐ table_cacheËƺõÉèÖõÃÌ«¸ßÁË¡£ÔÚ·åֵʱ¼ä£¬´ò¿ª±íµÄÊýÄ¿±È table_cacheÒªÉٵöࡣ
°¸Àý2£º¸Ã°¸ÀýÀ´×Ôһ̨¿ª·¢·þÎñÆ÷¡£
table_cache - 64
open_tables - 64
opened-tables - 431
uptime - 1662790 (measured in seconds)
ËäÈ» open_tablesÒѾµÈÓÚ table_cache£¬µ«ÊÇÏà¶ÔÓÚ·þÎñÆ÷ÔËÐÐʱ¼äÀ´Ëµ£¬ opened_tablesµÄÖµÒ²·Ç³£µÍ¡£Òò´Ë£¬Ôö¼Ó table_cacheµÄÖµÓ¦¸ÃÓô¦²»´ó¡£
°¸Àý3£º¸Ã°¸ÀýÀ´×ÔÒ»¸öupderperfµÄ·þÎñÆ÷
table_cache - 64
open_tables - 64
opened_tables - 22423
uptime - 19538
¸Ã°¸ÀýÖÐ table_cacheÉèÖõÃÌ«µÍÁË¡£ËäÈ»ÔËÐÐʱ¼ä²»µ½6Сʱ£¬ open_tables´ïµ½ÁË×î´óÖµ£¬ opened_tablesµÄÖµÒ²·Ç³£¸ß¡£ÕâÑù¾ÍÐèÒªÔö¼Ó table_cacheµÄÖµ¡£
key_buffer_size
key_buffer_sizeÖ¸¶¨Ë÷Òý»º³åÇøµÄ´óС£¬Ëü¾ö¶¨Ë÷Òý´¦ÀíµÄËٶȣ¬ÓÈÆäÊÇË÷Òý¶ÁµÄËٶȡ£Í¨¹ý¼ì²é״ֵ̬ Key_read_requestsºÍ Key_reads£¬¿ÉÒÔÖªµÀ key_buffer_sizeÉèÖÃÊÇ·ñºÏÀí¡£±ÈÀý key_reads / key_read_requestsÓ¦¸Ã¾¡¿ÉÄܵĵͣ¬ÖÁÉÙÊÇ1:100£¬1:1000¸üºÃ£¨ÉÏÊö״ֵ̬¿ÉÒÔʹÓÃSHOW STATUS LIKE ¡®key_read%¡¯»ñµÃ£©¡£
key_buffer_sizeÖ»¶ÔMyISAM±íÆð×÷Óᣠ¼´Ê¹Ä㲻ʹÓÃMyISAM ±í £¬µ«ÊÇÄÚ²¿µÄ ÁÙʱ´ÅÅ̱íÊÇMyISAM ±í£¬Ò²ÒªÊ¹ÓøÃÖµ¡£¿ÉÒÔʹÓüì²é״ֵ̬created_tmp_disk_tables µÃÖªÏêÇé¡£
¶ÔÓÚ1G ÄÚ´æµÄ»úÆ÷£¬Èç¹û²»Ê¹ÓÃMyISAM ±í£¬ÍƼöÖµÊÇ16M £¨8-64M £©¡£
°¸Àý1£º½¡¿µ×´¿ö
key_buffer_size - 402649088 (384M)
key_read_requests - 597579931
key_reads - 56188
°¸Àý2£º¾¯±¨×´Ì¬
key_buffer_size - 16777216 (16M)
key_read_requests - 597579931
key_reads - 53832731
°¸Àý1ÖбÈÀýµÍÓÚ1:10000£¬Êǽ¡¿µµÄÇé¿ö£»°¸Àý2ÖбÈÀý´ïµ½1:11£¬¾¯±¨ÒѾÀÏì¡£
ÓÅ»¯query_cache_size
´Ó4.0.1¿ªÊ¼£¬MySQLÌṩÁ˲éѯ»º³å»úÖÆ¡£Ê¹Óòéѯ»º³å£¬MySQL½«SELECTÓï¾äºÍ²éѯ½á¹û´æ·ÅÔÚ»º³åÇøÖУ¬½ñºó¶ÔÓÚͬÑùµÄSELECTÓï¾ä£¨Çø·Ö´óСд£©£¬½«Ö±½Ó´Ó»º³åÇøÖжÁÈ¡½á¹û¡£¸ù¾ÝMySQLÓû§ÊֲᣬʹÓòéѯ»º³å×î¶à¿ÉÒÔ´ïµ½238£¥µÄЧÂÊ¡£
ͨ¹ý¼ì²é״ֵ̬ Qcache_*£¬¿ÉÒÔÖªµÀ query_cache_sizeÉèÖÃÊÇ·ñºÏÀí£¨ÉÏÊö״ֵ̬¿ÉÒÔʹÓÃSHOW STATUS LIKE ¡®Qcache%¡¯»ñµÃ£©¡£Èç¹û Qcache_lowmem_prunesµÄÖµ·Ç³£´ó £¬Ôò±íÃ÷¾³£³öÏÖ»º³å²»¹»µÄÇé¿ö£¬Èç¹û Qcache_hitsµÄÖµÒ²·Ç³£´ó£¬Ôò±íÃ÷²éѯ»º³åʹÓ÷dz£Æµ·±£¬´ËʱÐèÒªÔö¼Ó»º³å´óС£»Èç¹û Qcache_hitsµÄÖµ²»´ó£¬Ôò±íÃ÷ÄãµÄ²éѯÖظ´Âʺܵͣ¬ÕâÖÖÇé¿öÏÂʹÓòéѯ»º³å·´¶ø»áÓ°ÏìЧÂÊ£¬ÄÇô¿ÉÒÔ¿¼ÂDz»Óòéѯ»º³å¡£´ËÍ⣬ÔÚSELECTÓï¾äÖмÓÈë SQL_NO_CACHE¿ÉÒÔÃ÷È·±íʾ²»Ê¹Óòéѯ»º³å¡£
Óë²éѯ»º³åÓйصIJÎÊý»¹ÓÐ query_cache_type¡¢ query_cache_limit¡¢ query_cache_min_res_unit¡£ query_cache_typeÖ¸¶¨ÊÇ·ñʹÓòéѯ»º³å£¬¿ÉÒÔÉèÖÃΪ0¡¢1¡¢2£¬¸Ã±äÁ¿ÊÇSESSION¼¶µÄ±äÁ¿¡£ query_cache_limitÖ¸¶¨µ¥¸ö²éѯÄܹ»Ê¹ÓõĻº³åÇø´óС£¬È±Ê¡Îª1M¡£ query_cache_min_res_unit ÊÇÔÚ4.1°æ±¾ÒÔºóÒýÈëµÄ£¬ËüÖ¸¶¨·ÖÅ仺³åÇø¿Õ¼äµÄ×îСµ¥Î»£¬È±Ê¡Îª4K¡£¼ì²é״ֵ̬ Qcache_free_blocks£¬Èç¹û¸ÃÖµ·Ç³£´ó£¬Ôò±íÃ÷»º³åÇøÖÐËéƬºÜ¶à£¬Õâ¾Í±íÃ÷²éѯ½á¹û¶¼±È½ÏС£¬´ËʱÐèÒª¼õС query_cache_min_res_unit ¡£
¿ªÆô¶þ½øÖÆÈÕÖ¾( Binary Log )
¶þ½øÖÆÈÕÖ¾°üº¬ËùÓиüÐÂÊý¾ÝµÄÓï¾ä£¬ÆäÄ¿µÄÊÇÔÚ»Ö¸´Êý¾Ý¿âʱÓÃËüÀ´°ÑÊý¾Ý¾¡¿ÉÄָܻ´µ½×îºóµÄ״̬¡£ÁíÍ⣬Èç¹û×öͬ²½¸´ÖÆ( Replication )µÄ»°£¬Ò²ÐèҪʹÓöþ½øÖÆÈÕÖ¾´«ËÍÐÞ¸ÄÇé¿ö¡£
¿ªÆô¶þ½øÖÆÈÕÖ¾£¬ÐèÒªÉèÖòÎÊý log-bin¡£ log_binÖ¸¶¨ÈÕÖ¾Îļþ£¬Èç¹û²»ÌṩÎļþÃû£¬MySQL½«×Ô¼º²úÉúȱʡÎļþÃû¡£MySQL»áÔÚÎļþÃûºóÃæ×Ô¶¯Ìí¼ÓÊý×ÖË÷Òý£¬Ã¿´ÎÆô¶¯·þÎñʱ£¬¶¼»áÖØÐÂÉú³ÉÒ»¸öеĶþ½øÖÆÎļþ¡£
´ËÍ⣬ʹÓà log-bin-index¿ÉÒÔÖ¸¶¨Ë÷ÒýÎļþ£»Ê¹Óà binlog-do-db¿ÉÒÔÖ¸¶¨¼Ç¼µÄÊý¾Ý¿â£»Ê¹Óà binlog-ignore-db¿ÉÒÔÖ¸¶¨²»¼Ç¼µÄÊý¾Ý¿â¡£×¢ÒâµÄÊÇ£º binlog-do-db ºÍbinlog-ignore-db Ò»´ÎÖ»Ö¸¶¨Ò»¸öÊý¾Ý¿â£¬Ö¸¶¨¶à¸öÊý¾Ý¿âÐèÒª¶à¸öÓï¾ä¡£¶øÇÒ£¬MySQL»á½«ËùÓеÄÊý¾Ý¿âÃû³Æ¸Ä³ÉСд£¬ ÔÚÖ¸¶¨Êý¾Ý¿âʱ±ØÐëÈ«²¿Ê¹ÓÃСдÃû×Ö£¬·ñÔò²»»áÆð×÷Óá£
ÔÚMySQLÖÐʹÓà SHOW MASTER STATUSÃüÁî¿ÉÒԲ鿴ĿǰµÄ¶þ½øÖÆÈÕ־״̬¡£
¿ªÆôÂý²éѯÈÕÖ¾( slow query log )
Âý²éѯÈÕÖ¾¶ÔÓÚ¸ú×ÙÓÐÎÊÌâµÄ²éѯ·Ç³£ÓÐÓá£Ëü¼Ç¼ËùÓвé¹ýlong_query_timeµÄ²éѯ£¬Èç¹ûÐèÒª£¬»¹¿ÉÒԼǼ²»Ê¹ÓÃË÷ÒýµÄ¼Ç¼¡£ÏÂÃæÊÇÒ»¸öÂý²éѯÈÕÖ¾µÄÀý×Ó£º
¿ªÆôÂý²éѯÈÕÖ¾£¬ÐèÒªÉèÖòÎÊýlog_slow_queries¡¢ long_query_times¡¢ log-queries-not-using-indexes ¡£log_slow_queriesÖ¸¶¨ÈÕÖ¾Îļþ£¬Èç¹û²»ÌṩÎļþÃû£¬MySQL½«×Ô¼º²úÉúȱʡÎļþÃû¡£ long_query_timesÖ¸¶¨Âý²éѯµÄãÐÖµ£¬È±Ê¡ÊÇ10Ãë¡£ log-queries-not-using-indexesÊÇ4.1.0ÒÔºóÒýÈëµÄ²ÎÊý£¬Ëüָʾ¼Ç¼²»Ê¹ÓÃË÷ÒýµÄ²éѯ¡£
ÅäÖÃInnoDB
Ïà¶ÔÓÚMyISAM±íÀ´Ëµ£¬ÕýÈ·ÅäÖòÎÊý¶ÔÓÚInnoDB±í¸ü¼Ó¹Ø¼ü¡£ÆäÖУ¬×îÖØÒªµÄ²ÎÊýÊÇ innodb_data_file_path¡£ËüÖ¸¶¨±íÊý¾ÝºÍË÷Òý´æ´¢µÄ¿Õ¼ä£¬¿ÉÒÔÊÇÒ»¸ö»òÕ߶à¸öÎļþ¡£×îºóÒ»¸öÊý¾ÝÎļþ±ØÐëÊÇ×Ô¶¯À©³äµÄ£¬Ò²Ö»ÓÐ×îºóÒ»¸öÎļþÔÊÐí×Ô¶¯À©³ä¡£ÕâÑù£¬µ±¿Õ¼äÓÃÍêºó£¬×Ô¶¯À©³äÊý¾ÝÎļþ¾Í»á×Ô¶¯Ôö³¤£¨ÒÔ8MBΪµ¥Î»£©ÒÔÈÝÄɶîÍâµÄÊý¾Ý¡£ÀýÈç £º
innodb_data_file_path=/disk1/ibdata1:900M;/disk2/ibdata2:50M:autoextend
Á½¸öÊý¾ÝÎļþ·ÅÔÚ²»Í¬µÄ´ÅÅÌÉÏ¡£Êý¾ÝÊ×ÏÈ·ÅÔÚibdata1ÖУ¬µ±´ïµ½900MÒÔºó£¬Êý¾Ý¾Í·ÅÔÚibdata2ÖС£Ò»µ©´ïµ½50MB£¬ibdata2½«ÒÔ8MBΪµ¥Î»×Ô¶¯Ôö³¤¡£
Èç¹û´ÅÅÌÂúÁË£¬ÄãÐèÒªÔÚÁíÍâµÄ´ÅÅÌÉÏÃæÔö¼ÓÒ»¸öÊý¾ÝÎļþ¡£Îª´Ë£¬ÄãÐèÒª²é¿´×îºóÒ»¸öÎļþµÄ³ß´ç£¬È»ºó¼ÆËã×î½Ó½üµÄÕûÊý£¨MB£©¡£È»ºóÊÖ¹¤Ð޸ĸÃÎļþµÄ´óС£¬²¢Ìí¼ÓеÄÊý¾ÝÎļþ¡£ÀýÈ磺¼ÙÉèibdata2ÒѾÓÐ109MBÊý¾Ý£¬ÄÇô¿ÉÒÔÐÞ¸ÄÈçÏ£º
innodb_data_file_path=/disk1/ibdata1:900M;/disk2/ibdata2:109M;/disk3/ibdata3:500M:autoextend
flush_time
Èç¹ûϵͳÓÐÎÊÌâ²¢ÇÒ¾³£ËøËÀ»òÖØÐÂÒýµ¼£¬Ó¦½«¸Ã±äÁ¿ÉèÖÃΪ·ÇÁãÖµ£¬Õ⽫µ¼Ö·þÎñÆ÷°´flush_time ÃëÀ´Ë¢Ð±íµÄ¸ßËÙ»º´æ¡£ÓÃÕâÖÖ·½·¨À´Ð´³ö¶Ô±íµÄÐ޸Ľ«½µµÍÐÔÄÜ£¬µ«¿É¼õÉÙ±í¶ïÎó»òÊý¾Ý¶ªÊ§µÄ»ú»á¡£
Ò»°ãʹÓÃȱʡֵ¡£
Binlog_cache_size
The size of the cache to hold the SQL statements for the binary log during a transaction. A binary log cache is allocated for each client if the server supports any transactional storage engines and if the server has binary log enabled(--log-bin option). If you often use big, multiple-statement transactions, you can increase this to get more perf The Binlog_cache_use and Binlog_cache_disk_use status variables can be useful for tuning the size of this variable.
3£®´æ´¢ÒýÇæ
ÔÚMYSQL 3.23.0 °æ±¾ÖУ¬ÒýÈëÁËMyISAM ´æ´¢ÒýÇæ¡£ËüÊÇÒ»¸ö·ÇÊÂÎñÐ͵Ĵ洢ÒýÇ棬³ÉΪÁËMYSQL µÄȱʡ´æ´¢ÒýÇæ¡£µ«ÊÇ£¬Èç¹ûʹÓÃÉèÖÃÏòµ¼À´ÉèÖòÎÊý£¬ÔòËü»á°ÑInnoDB ×÷ΪȱʡµÄ´æ´¢ÒýÇæ¡£InnoDB ÊÇÒ»¸öÊÂÎñÐ͵Ĵ洢ÒýÇæ¡£
´´½¨±íµÄʱºò£¬¿ÉÒÔΪ±íÖ¸¶¨´æ´¢ÒýÇ棬Óï·¨ÈçÏ£º
CREATE TABLE t (i INT) ENGINE = MyISAM
CREATE TABLE t (i INT) TYPE = MyISAM
Èç¹ûûÓÐÖ¸¶¨£¬ÔòʹÓÃȱʡµÄ´æ´¢ÒýÇæ¡£Ò²¿ÉÒÔʹÓÃALTER TABLE À´¸ü»»±íÒýÇ棬Óï·¨ÈçÏ£º
ALTER TABLE t ENGINE = MyISAM
ͬһÊý¾Ý¿âÖпÉÒÔ°üº¬²»Í¬´æ´¢ÒýÇæµÄ±í¡£