Mysql Query挂在生产数据库服务器上但在本地工作正常

时间:2011-01-01 18:05:50

标签: mysql database performance debugging

我遇到了一个我自己无法解决的问题。我有一个运行mysql 5.1.37的amazon EC2服务器(大型实例)和一个rails应用程序。服务器最近一直遇到数据库进程挂起和高CPU使用的问题,当我进入mysql控制台并执行show完整进程列表时,我看到它挂起了这样的查询发送数据:

| 315 | root | 10.249.61.118:47812 | roomorama | Query   |  193 | Sending data | SELECT COUNT(*) FROM (SELECT `rooms`.*, IFNULL(MIN(av.host_daily_price), rooms.host_daily_price) AS 'price' FROM `rooms` LEFT JOIN availabilities AS av ON (av.room_id = rooms.id AND av.date BETWEEN '2011-01-01' AND '2011-07-01' AND av.inquiry_id IS NULL AND (av.status IS NULL OR av.status = 0)) WHERE (rooms.deleted_at IS NULL) AND (`rooms`.`city_id` = 1 AND `rooms`.`hidden` = 0) AND (`rooms`.`created_at` <= '2011-01-01 16:54:43') GROUP BY rooms.id) as search_results |

这似乎根本没有回归,或者花了很长时间才完成。 在我的开发机器(相同的mysql版本)上运行此查询在本地快速返回结果,但没有问题。 我不知道从哪里开始寻找,这是一个mysql错误吗?一个配置非常糟糕的mysql服务器? 表是innodb,这是我在服务器上的完整mysql配置文件

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp

character-set-server            = utf8
default-character-set           = utf8

default-storage-engine=innodb
skip-external-locking
skip-name-resolve
skip-federated

bind-address            = 0.0.0.0

#
# * Fine Tuning
#

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover          = BACKUP

#thread_concurrency     = 10
max_allowed_packet      = 32M
thread_stack            = 192K
thread_cache_size       = 8
key_buffer              = 250M
max_connections         = 1024
wait_timeout            = 180
net_read_timeout        = 30
net_write_timeout       = 30
back_log                = 128
table_cache             = 1024
max_heap_table_size     = 512M                                                                                                                                              

#
# * InnoDB Tuning
#

innodb_buffer_pool_size         = 5000M
innodb_additional_mem_pool_size = 20M
innodb_flush_log_at_trx_commit  = 2
innodb_lock_wait_timeout        = 50
#innodb_log_file_size=250M
#innodb_log_buffer_size=8M


#
# * Query Cache Configuration
#

# Query Cache
query_cache_limit      = 4M
query_cache_size       = 256M
query_cache_type       = 1


#
# * Slow Query Logging
#
log_slow_queries       = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes

# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name



[mysqldump]
quick
quote-names

max_allowed_packet      = 32M
default-character-set   = utf8

[mysql]
default-character-set   = utf8

[isamchk]
key_buffer              = 16M

2 个答案:

答案 0 :(得分:1)

您的开发服务器可能有不同的数据集吗?请记住,查询完成所需的时间取决于数据库中行的数量和内容。

答案 1 :(得分:0)

您应该查看表的索引。我刚才遇到了同样的问题,发现我在本地表上缺少一个索引。