我在一台 512MB 的 Debian 7.5 服务器上。我醒来发现它mysqld
没有运行,并且syslog
显示如下行:
Aug 9 09:00:58 web kernel: [1086155.903755] Out of memory: Kill process 2669 (m
ysqld) score 139 or sacrifice child
Aug 9 09:00:58 web kernel: [1086155.903920] Killed process 2669 (mysqld) total-
vm:448964kB, anon-rss:70396kB, file-rss:0kB
Aug 9 09:00:59 web mysqld_safe: Number of processes running now: 0
Aug 9 09:00:59 web mysqld_safe: mysqld restarted
[...]
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: The InnoDB memory heap is disabled
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Compressed tables use zlib 1.2.7
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Using Linux native AIO
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Initializing buffer pool, size = 128.0M
Aug 9 09:01:01 web mysqld: InnoDB: mmap(137363456 bytes) failed; errno 12
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Completed initialization of buffer pool
Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Fatal error: cannot allocate memory for the buffer pool
Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Plugin 'InnoDB' init function returned error.
Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Unknown/unsupported storage engine: InnoDB
Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Aborting
Aug 9 09:01:01 web mysqld:
Aug 9 09:01:01 web mysqld: 140809 9:01:01 [Note] /usr/sbin/mysqld: Shutdown complete
Aug 9 09:01:01 web mysqld:
Aug 9 09:01:02 web mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
Aug 9 11:08:44 web mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
[...]
Aug 9 11:08:44 web mysqld: 140809 11:08:44 InnoDB: Database was not shut down normally!
Aug 9 11:08:44 web mysqld: InnoDB: Starting crash recovery.
Aug 9 11:08:44 web mysqld: InnoDB: Reading tablespace information from the .ibd files...
Aug 9 11:08:44 web mysqld: InnoDB: Restoring possible half-written data pages from the doublewrite
Aug 9 11:08:44 web mysqld: InnoDB: buffer...
然后出现一堆警告,说各种表被标记为崩溃。然而,当我进入mysql
并运行时check table <table name>;
,它说没问题。
看起来内存配置有误。这是我的/etc/mysql/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 = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * 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 logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# 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 = 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
#
# * 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_size = 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/
任何帮助巨大地非常感谢!这是一台生产服务器,我不能容忍 mysql 服务器随机启动然后死机。谢谢!
答案1
这是没有注释和空白行[mysqld]
的部分my.cnf
[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
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 127.0.0.1
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover-options = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
您已经使用连接、InnoDB 存储引擎和每个连接内存设置(sort_buffer_size、join_buffer_size、read_buffer_size、read_rnd_buffer_size)的基本功能运行了 mysqld,因为这些选项均未设置。因此,它们使用默认值运行。
您从系统日志中发布的内容无法明确指出操作系统中的其他内容(其他进程)是罪魁祸首。尽管如此,您只是需要更多 RAM。我确信排除 mysqld 是原因。它只是内存不足场景的受害者。
如果您觉得 mysqld 涉及更深层次的问题,请查看错误日志。如果内存泄漏是问题的一部分,它应该已经转储了内存跟踪。由于您没有在 中设置错误日志文件,因此您应该能够以主机名作为错误日志文件的前缀my.cnf
在 中找到错误日志。/var/log/mysql