MYSQL调优

时间:2023-03-09 18:09:23
MYSQL调优

4核8G内存配置文件

explain SQL 查看SQL索引使用情况。

my.cnf
skip-external-locking
skip-name-resolve
back_log=
key_buffer_size=512M
max_allowed_packet=4M
thread_stack=256k
table_cache=614k
sort_buffer_size=6M
read_buffer_size=4M
join_buffer_size=8M
myisam_sort_buffer_size=64M
thread_cache_size=
query_cache_size=64M
tmp_table_size=256M
max_connections=
max_connect_errors=
wait_timeout=
thread_concurrency=
innodb_additional_mem_pool_size=4M
innodb_log_buffre_size=2M
innodb_thread_concurrency=
read_rnd_buffer_size=16M

查看次数最多的20条SQL   : mysqldumpslow -s c -t 20 host -slow.log

查看最大连接数: show variables like 'max_connections';

当前连接数:show global status like 'Max_used_connections';

查看索引使用率:show global status like 'key_read%';     key_reads/key_read_requests * 100%。

查看临时表的使用情况:show global status like 'created_tmp%';

查看在内存上的临时表:show variables where Variable_name in ('tmp_table_size', 'max_heap_table_size');  如果超过该值将写入硬盘

查看mysql进程使用情况:Threads_created  如果过大说明一直在创建进程浪费资源,需要加大:thread_cache_size=64.

mysql> show global status like 'Thread%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 9     |
| Threads_connected | 11    |
| Threads_created   | 7092  |
| Threads_running   | 1     |
+-------------------+-------+
4 rows in set (0.00 sec)

tuning-primer.sh mysql 报表  优化检测工具:http://www.cnblogs.com/zengkefu/p/5638666.html  wget http://www.day32.com/MySQL/tuning-primer.sh

查看表索引使用情况:explain select * from xxxxxx

          查看:rows  项 扫描数据行记录。

          key:索引项目。