由于 InnoDB 无法分配内存导致 Mysql 崩溃

由于 InnoDB 无法分配内存导致 Mysql 崩溃

我认为,MySQL 时不时崩溃的原因是,一个较大的请求超过了 my.cnf 中设置的 innodb-buffer-pool-size(当前为 210M),而我需要首先设置该值才能启动 mysql。

以下是错误日志:

    130518 17:28:52 mysqld_safe Number of processes running now: 0
    130518 17:28:52 mysqld_safe mysqld restarted
    130518 17:28:52 [Note] Plugin 'FEDERATED' is disabled.
    130518 17:28:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130518 17:28:52 InnoDB: Compressed tables use zlib 1.2.3
    130518 17:28:52 InnoDB: Using Linux native AIO
    130518 17:28:52 InnoDB: Initializing buffer pool, size = 210.0M
    InnoDB: mmap(223117312 bytes) failed; errno 12
    130518 17:28:52 InnoDB: Completed initialization of buffer pool
    130518 17:28:52 InnoDB: Fatal error: cannot allocate memory for the buffer pool
    130518 17:28:52 [ERROR] Plugin 'InnoDB' init function returned error.
    130518 17:28:52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    130518 17:28:52 [ERROR] Unknown/unsupported storage engine: InnoDB
    130518 17:28:52 [ERROR] Aborting

    130518 17:28:52 [Note] /usr/libexec/mysqld: Shutdown complete

    130518 17:28:52 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

重启服务器并重启mysqld。暂时修复了问题,但是会再次崩溃。

    130518 18:22:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    130518 18:22:32 [Note] Plugin 'FEDERATED' is disabled.
    130518 18:22:32 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    130518 18:22:32 InnoDB: Compressed tables use zlib 1.2.3
    130518 18:22:32 InnoDB: Using Linux native AIO
    130518 18:22:32 InnoDB: Initializing buffer pool, size = 210.0M
    130518 18:22:32 InnoDB: Completed initialization of buffer pool
    130518 18:22:32 InnoDB: highest supported file format is Barracuda.
    InnoDB: The log sequence number in ibdata files does not match
    InnoDB: the log sequence number in the ib_logfiles!
    130518 18:22:32  InnoDB: Database was not shut down normally!
    InnoDB: Starting crash recovery.
    InnoDB: Reading tablespace information from the .ibd files...
    InnoDB: Restoring possible half-written data pages from the doublewrite
    InnoDB: buffer...
    130518 18:22:32  InnoDB: Waiting for the background threads to start
    130518 18:22:33 InnoDB: 5.5.31 started; log sequence number 789470772
    130518 18:22:33 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
    130518 18:22:33 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
    [mysqld]
    130518 18:22:33 [Note] Server socket created on IP: '0.0.0.0'.
    130518 18:22:33 [ERROR] Missing system table mysql.proxies_priv; please run mysql_upgrade to create it
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_current' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_history' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_history_long' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'setup_consumers' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'setup_instruments' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'setup_timers' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'performance_timers' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'threads' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_thread_by_event_name' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_instance' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'events_waits_summary_global_by_event_name' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'file_summary_by_event_name' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'file_summary_by_instance' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'mutex_instances' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'rwlock_instances' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'cond_instances' has the wrong structure
    130518 18:22:33 [ERROR] Native table 'performance_schema'.'file_instances' has the wrong structure
    130518 18:22:33 [Note] Event Scheduler: Loaded 0 events
    130518 18:22:33 [Note] /usr/libexec/mysqld: ready for connections.
    Version: '5.5.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL) by Remi

这是我的 my.cnf:pastebin.com/SSeU8gxK

答案1

添加以下参数并检查问题是否解决:
innodb_buffer_pool_instances=3
innodb_change_buffering=inserts
innodb_flush_method=O_DIRECT

相关内容