MySQL使用所有的内存,并进入交换

我们有一个专用的Linux服务器,用于我们的mysql数据库。 我们运行的任何脚本都遇到了可怕的速度问题,随着时间的推移,似乎会越来越糟糕,因为我们运行的脚本越来越多。 我可以在本地机器上运行这些脚本,并且运行速度会提高一倍。

现在看来,我们有一个记忆问题。 当我们继续运行脚本时,内存使用率变得更高(这显然是正常的),但是当这些脚本结束时,它们不释放内存。 注*这不是caching的内存。

我不能发布任何图像,因为我有0个rep点,但运行htop显示我目前使用28245 / 32150MB,再次 – 这不是caching内存和脚本当前正在运行。

任何帮助将不胜感激。

从服务器my.cnf:

# # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # 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 lc-messages-dir = /usr/share/mysql #skip-external-locking # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 41.76.208.223 #bind-address = 127.0.0.1 # # * Fine Tuning # key_buffer = 384M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 384 skip-name-resolve # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 table_cache = 1500 table_definition_cache = 1500 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 4M query_cache_size = 128M join_buffer_size = 128M max_heap_table_size = 128M tmp_table_size = 128M read_buffer_size = 32M innodb_buffer_pool_size = 25G # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # # Here you can see queries with especially long duration #log_slow_queries = /var/log/mysql/mysql-slow.log #long_query_time = 2 #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 = 2 log_bin = /var/log/mysql/mysql-bin.log log_bin_index = /var/log/mysql/mysql-bin.log.index relay_log = /var/log/mysql/mysql-relay-bin relay_log_index = /var/log/mysql/mysql-relay-bin.index expire_logs_days = 10 max_binlog_size = 100M log_slave_updates = 1 auto-increment-increment = 2 auto-increment-offset = 1 replicate-ignore-db = mysql replicate-ignore-db = information_schema replicate-ignore-db = performance_schema #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ 

看看这里的configuration,mysql会占用机器上几乎所有的内存 – 如果它是一个只运行InnoDB的专用MySQL服务器,那么它应该如何configuration。

但是当这些结束时,他们不释放内存

他们不会从innodb缓冲池中释放内存 – 这就是系统打算工作的方式。

如果你的系统正在使用交换,那么任何一个mysql都在某处泄漏(你忘了告诉我们你使用的是什么版本)。 更有可能的是,别的东西正在使用大量的内存,而不是释放它。

是“innodb_buffer_pool_size = 25G”吗?

使用数据库的内部caching使得数据库工作更快,但是以减慢所有其他服务为代价,因为系统无法回收该内存,不能将其用于文件系统caching,不能将其用于进程。 尝试降低你的MySQL的胃口。