52. innodb_flush_log_at_trx_commit 0 – write log buffer to file and flush it to disk every second 1 – write&flush to disk for every transaction 2 – write for every transaction and flush every second Settings
59. SLOW QUERIES Current long_query_time = 10 sec. You have 526 out of 36204146 that take longer than 10 sec. to complete The slow query log is NOT enabled. Your long_query_time may be too high, I typically set this under 5 sec. tuning-primer.sh
60. QUERY CACHEQuery cache is enabledCurrent query_cache_size = 8 MCurrent query_cache_used = 7 MCurrent query_cach_limit = 1 MCurrent Query cache fill ratio = 89.38 %However, 254246 queries have been removed from the query cache due to lack of memoryPerhaps you should raise query_cache_sizeMySQL won't cache query results that are larger than query_cache_limit in size tuning-primer.sh
61. TEMP TABLES Current max_heap_table_size = 16 M Current tmp_table_size = 32 M Of 35170 temp tables, 74% were created on disk Effective in-memory tmp_table_size is limited to max_heap_table_size. Perhaps you should increase your tmp_table_size and/or max_heap_table_size to reduce the number of disk-based temporary tables Note! BLOB and TEXT columns are not allow in memory tables. If you are using these columns raising these values might not impact your ratio of on disk temp tables. tuning-primer.sh
63. -------- Storage Engine Statistics --------------------- [--] Status: -Archive +BDB -Federated +InnoDB -ISAM -NDBCluster [--] Data in MyISAM tables: 19M (Tables: 90) [!!] InnoDB is enabled but isn't being used [!!] BDB is enabled but isn't being used [!!] Total fragmented tables: 18 mysql-tuner.pl
64. -------- Performance Metrics --------------------------- [--] Up for: 16m 37s (6K q [6.059 qps], 146 conn, TX: 54M, RX: 665K) [--] Reads / Writes: 62% / 38% [--] Total buffers: 298.0M global + 6.3M per thread (100 max threads) [OK] Maximum possible memory usage: 929.2M (26% of installed RAM) [OK] Slow queries: 0% (0/6K) [OK] Highest usage of available connections: 5% (5/100) [OK] Key buffer size / total MyISAM indexes: 256.0M/2.3M [!!] Key buffer hit rate: 91.3% (1K cached / 101 reads) [OK] Query cache efficiency: 97.6% (5K cached / 5K selects) mysql-tuner.pl
65. -------- Recommendations ------------------------------- General recommendations: Add skip-innodb to MySQL configuration to disable InnoDB Add skip-bdb to MySQL configuration to disable BDB Run OPTIMIZE TABLE to defragment tables for better performance MySQLstarted within last 24 hours - recommendations may be inaccurate Enable the slow query log to troubleshoot bad queries mysql-tuner.pl
68. maatkit: mk-error-log Count Level Message ===== ======= ======================================= 5 info mysqld started 4 info mysqld version info 3 info InnoDB: Started 2 info mysqld ended 1 unknown Number of processes running now: 0 1 error [ERROR] /usr/sbin/mysqld: unknown variable 'ssl-ke 1 error [ERROR] Failed to initialize the master info struc
69. maatkit: mk-log-player mk-log-player does two things: it splits MySQL query logs into session files and it plays (executes) queries in session files on a MySQL server.
70. maatkit: mk-index-usage This tool connects to a MySQL database server, reads through a query log, and uses EXPLAIN to ask MySQL how it will use each query. When it is finished, it prints out a report on indexes that the queries didn't use.
71. maatkit: mk-query-advisor mk-query-advisor examines queries and applies rules to them, trying to find queries that look bad according to the rules. It reports on queries that match the rules, so you can find bad practices or hidden problems in your SQL.
72. maatkit: mk-query-digest # pct total min max avg 95% stddev median # Count 0 2 # Exec time 13 1105s 552s 554s 553s 554s 2s 553s # Lock time 0 216us 99us 117us 108us 117us 12us 108us # Rows sent 20 6.26M 3.13M 3.13M3.13M3.13M 12.73 3.13M # Rows exam 0 6.26M 3.13M 3.13M3.13M3.13M 12.73 3.13M … # Query_time distribution # 1us # 10us # 100us # 1ms # 10ms # 100ms # 1s # 10s+ #############################################################
73. maatkit: mk-query-profiler mk-query-profiler reads a file containing one or more SQL statements or shell commands, executes them, and analyzes the output of SHOW STATUS afterwards. It then prints statistics about how the batch performed. For example, it can show how many table scans the batch caused, how many page reads, how many temporary tables, and so forth.
81. CREATE TABLE employee ( employee_number char(10) NOT NULL, firstnamevarchar(40), surname varchar(40), address text, tel_novarchar(25), salary int(11), overtime_rateint(10) NOT NULL ); use Indexes
82. use Indexes NOT using PRIMARY KEY Using PRIMARY KEY EXPLAIN SELECT employee_number, firstname, surname FROM employee WHERE id=1000 id: 1 select_type: SIMPLE table: employee type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: id: 1 select_type: SIMPLE table: employee type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 10000 Extra: Using where
83. use Indexes ALTER TABLE employee ADD INDEX(surname, firstname); SELECT overtime_rate FROM employee WHERE surname='Madida'; SELECT overtime_rate FROM employee WHERE firstname='Mpho'; SELECT overtime_rate FROM employee WHERE surname='Madida' and firstname="Mpho"; SELECT overtime_rate FROM employee WHERE firstname="Mpho" and surname='Madida';
84. use Indexes ALTER TABLE employee ADD INDEX(surname, firstname); SELECT overtime_rate FROM employee WHERE surname='Madida'; SELECT overtime_rate FROM employee WHERE firstname='Mpho'; SELECT overtime_rate FROM employee WHERE surname='Madida' and firstname="Mpho"; SELECT overtime_rate FROM employee WHERE firstname="Mpho" and surname='Madida';
85. use Indexesand be concrete select … WHERE year(my_date) > 2010 select … where email LIKE “%@gmail.com” select * from table; select * from table limit 10000; select col1 from table where id > 0; insert into table values(‘1’, ‘bla’);
86. create table `ids` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id1` int(11) NOT NULL, `id2` int(11) DEFAULT NULL, …, PRIMARY KEY (`id`) ) ENGINE=InnoDB; SELECT COUNT(*) FROM `ids`; SELECT COUNT(`id`) FROM `ids`; SELECT COUNT(`id1`) FROM `ids`; SELECT COUNT(`id2`) FROM `ids`; get a map!