有一个后台daemon程序,运行期一直保持着数据库连接。并有频繁的数据插入。
数据库有500多个表,都会被频繁的使用。
数据库运行一段时间就会发现,8G的内存竟然会被吃光了。配置文件使用的是默认的my-medium.cnf文件。
希望大虾能够提示,这个问题应该从哪些方面考虑解决。
谢谢数据库版本信息:
Server version: 5.1.46-log Source distributionmy.cnf文件,去除了中间部分注释

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/var) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin# binary logging format - mixed recommended
binlog_format=mixed
server-id       = 1
[mysqldump]
quick
max_allowed_packet = 16M[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M[mysqlhotcopy]

解决方案 »

  1.   

    先检查一下你的SESSION数,是不是有太多并发连接了?
      

  2.   

    mysql> show processlist;
    +------+----------+---------------------+--------------------+---------+------+-------+------------------+
    | Id   | User     | Host                | db                 | Command | Time | State | Info             |
    +------+----------+---------------------+--------------------+---------+------+-------+------------------+
    |  803 | monitor  | 122.11.48.133:34882 | dn_monitor         | Sleep   |  223 |       | NULL             |
    | 1113 | monitor  | 122.11.48.138:45172 | dn_monitor         | Sleep   |    4 |       | NULL             |
    | 1114 | monitor  | 122.11.48.138:45173 | dn_monitor         | Sleep   |    4 |       | NULL             |
    | 1115 | iamadmin | 127.0.0.1:35192     | dn_monitor         | Sleep   |   19 |       | NULL             |
    | 1116 | iamadmin | 127.0.0.1:35193     | dn_monitor         | Sleep   |   19 |       | NULL             |
    | 1117 | iamadmin | 127.0.0.1:35194     | dn_monitor         | Sleep   |   19 |       | NULL             |
    | 1118 | iamadmin | 127.0.0.1:35195     | dn_monitor         | Sleep   |   19 |       | NULL             |
    | 1119 | iamadmin | 127.0.0.1:35196     | dn_monitor         | Sleep   |   19 |       | NULL             |
    | 1120 | monitor  | 58.221.148.162:1899 | information_schema | Sleep   | 1355 |       | NULL             |
    | 1451 | root     | localhost           | NULL               | Query   |    0 | NULL  | show processlist |
    +------+----------+---------------------+--------------------+---------+------+-------+------------------+
    10 rows in set (0.00 sec)session看上去没太大的异常啊
      

  3.   

    补充一下系统信息啊:
    Linux 2.6.9-42.ELsmp
    64位
    CPU: Intel(R) Xeon(R) CPU   E5405  @ 2.00GHz
      

  4.   

    用lsof 跟一下你的mysql
      

  5.   

    # lsof | grep mysql | wc -l
    254
    同时
    table_open_cache 值为 256  
    应该不存在打开文件过多的问题。
      

  6.   

    在运行过程中查看top信息,发现cached在不断的增大。
    请教会不会是由于频繁的数据插入导致的?
      

  7.   

    很惭愧 
    刚弄清楚,系统的8G内存并不是被mysql吃掉的。
    只是被系统给cached起来了。
    mysql实际上占用的内存只有300多个M。
      

  8.   

    msyql占用内存大概就是innodb的缓存+myisam缓存+每个连接占用内存乘以连接数
      

  9.   

    你使用innodb的话应该设置innodb_buffer_pool参数,否则的话将key_buffer_size设置到内存的%80左右