我在专用服务器上托管了一个小型网站(FreeBSD 9.2、MySQL 5.6.1 和 php 5.5.5)。问题是,即使网站访客不多,MySQL 也会占用大量 CPU 资源。数据库很小(最大的表大约有 12k 行)
我已经在 my.conf 中启用了慢查询日志,但没有记录查询。
错误日志文件不包含任何有用的信息(实际上它是空的)
以下是服务器规格
中央处理器
hw.machine: amd64
hw.model: Intel(R) Xeon(R) CPU X3330 @ 2.66GHz
hw.ncpu: 4
hw.machine_arch: amd64
HHD 转移信息
Seek times:
Full stroke: 250 iter in 1.507837 sec = 6.031 msec
Half stroke: 250 iter in 1.461401 sec = 5.846 msec
Quarter stroke: 500 iter in 5.829283 sec = 11.659 msec
Short forward: 400 iter in 2.668680 sec = 6.672 msec
Short backward: 400 iter in 3.261849 sec = 8.155 msec
Seq outer: 2048 iter in 0.247219 sec = 0.121 msec
Seq inner: 2048 iter in 0.246036 sec = 0.120 msec
Transfer rates:
outside: 102400 kbytes in 1.207812 sec = 84781 kbytes/sec
middle: 102400 kbytes in 1.342168 sec = 76294 kbytes/sec
inside: 102400 kbytes in 1.893578 sec = 54078 kbytes/sec
I/O command overhead:
time to read 10MB block 0.131751 sec = 0.006 msec/sector
time to read 20480 sectors 2.170542 sec = 0.106 msec/sector
calculated command overhead
= 0.100 msec/sector
顶部(负载较高时)
Mem: 1518M Active, 1396M Inact, 732M Wired, 50M Cache, 435M Buf, 239M Free
4949 mysql 27 52 0 2236M 1434M uwait 3 180:02 66.26% mysqld
我的cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
skip-external-locking
max_connections=5000
max_connect_errors=1500
ft_min_word_len = 2
myisam_sort_buffer_size = 64M
# Log slow queries
slow_query_log = 1
slow_query_log_file = /var/log/slow-queries.log
long_query_time = 1
key_buffer = 384M
max_allowed_packet = 32M
thread_stack = 128K
thread_cache_size = 128
thread_concurrency = 16
wait_timeout = 2000
interactive_timeout = 10000
join_buffer_size = 1M
sort_buffer_size = 2M
read_buffer_size = 1M
read_rnd_buffer_size = 2M
query_cache_size = 268435456
query_cache_type=1
query_cache_limit=1048576
我不知道出了什么问题。
答案1
一些常规故障排除技巧:
- 检查您是否有其他/未知/外部数据库连接(例如
netstat -tapn
:) - 使用和检查正在运行的查询和服务器的状态
mysqladmin processlist
,mysqladmin process status
这可能会导致在表中添加索引。 - 检查慢查询日志(你已经这样做了)
- 检查mysql错误日志(你已经这样做了)
- 检查服务器的 RAM 内存和可用磁盘空间的一般状态:
free -m
,df -h
- 如果有可用内存,请增加
innodb_buffer_pool_size
配置文件中的值,以便有更多的缓存