所以这个让我很困惑。 2天前,我们服务器上的几乎所有查询都变得很慢。每次提供页面时,都会对慢速查询日志进行修改。
让我感到困惑的是,我们没有一张特别大的桌子,只有15,000个左右的条目,而且(据我所知),索引并不是一个问题。在PHPMYADMIN中运行相同的查询几乎在零时间内完成。
表用户有Id,Name,Country,AccID,crmstatus,modified_time,last_comment和调用。
服务器有8个内核和16GB内存。
这是我们的my.cnf:
[mysqld]
skip-name-resolve
innodb_file_per_table=1
innodb_buffer_pool_size=134217728
max_allowed_packet=268435456
open_files_limit = 1024000
query_cache_type = 1
innodb_buffer_pool_instances = 3
slow-query-log = 1
long_query_time = 0.5
query_cache_size=1G
join_buffer_size=16M
tmp_table_size=512M
max_heap_table_size=1G
thread_cache_size=8
table_open_cache=4096
innodb_buffer_pool_size=3G
key_buffer_size=256M
query_cache_limit=512M
tmp_table_size=512M
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
log_error = /var/log/mysqlerror.log
default-storage-engine=MyISAM
bind-address = 127.0.0.1
这是最后几个慢查询,这真的不应该。
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 1.352077 Lock_time: 0.000062 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820458;
update `users` set `modified_time` = '2016-06-13 12:20:57', `last_comment` = '2016-06-13 12:20:57' where `id` = '50045170';
# Time: 160613 14:21:28
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 1.613013 Lock_time: 0.000041 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820488;
update users set calls = calls+1, modified_time="2016-06-13 12:21:26" where id = '50045127';
# Time: 160613 14:21:47
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 9.126265 Lock_time: 0.000055 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820507;
update `users` set `modified_time` = '2016-06-13 12:21:38', `last_comment` = '2016-06-13 12:21:38' where `id` = '50037097';
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 9.051441 Lock_time: 0.000053 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820507;
update users set calls = calls+1, modified_time="2016-06-13 12:21:38" where id = '50045104';
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 6.198130 Lock_time: 0.000042 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820507;
update `users` set `modified_time` = '2016-06-13 12:21:41', `last_comment` = '2016-06-13 12:21:41' where `id` = '50015310';
# Time: 160613 14:22:03
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 1.770877 Lock_time: 0.000074 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820523;
update users set calls = calls+1, modified_time="2016-06-13 12:22:01" where id = '50045235';
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 0.564553 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820523;
update users set calls = calls+1, modified_time="2016-06-13 12:22:02" where id = '50045126';
# Time: 160613 14:22:29
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 11.289152 Lock_time: 0.000064 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820549;
update users set calls = calls+1, modified_time="2016-06-13 12:22:18" where id = '50045232';
# User@Host: REMOVED[REMOVED] @ localhost []
# Query_time: 11.016395 Lock_time: 0.000085 Rows_sent: 0 Rows_examined: 1
SET timestamp=1465820549;
update `users` set `crmstatus` = 'Decline', `modified_time` = '2016-06-13 12:22:18' where `id` = '50045055';
答案 0 :(得分:0)
哎哟!
innodb_buffer_pool_size=134217728 -- (should remove)
innodb_buffer_pool_size=3G
query_cache_type = 1 -- usually a waste on production servers
query_cache_size=1G -- TERRIBLE! Don't go over about 50M
tmp_table_size=512M -- Dangerously high - suggest 100M
max_heap_table_size=1G -- Dangerously high - suggest 100M
key_buffer_size=256M
tmp_table_size=512M -- redundant
log_error = /var/log/mysqlerror.log -- typo?
default-storage-engine=MyISAM -- InnoDB is preferred
请提供SHOW CREATE TABLE users
- 需要查看引擎和索引。
您使用的是哪个版本的MySQL?