刚发现测试机的数据库挂了,查看状态和启动均报错,信息大致如下:

[root@localhost ~]# service mysql status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]

[root@localhost var]# service mysql start
Starting MySQL.The server quit without updating PID file (/usr/local/mysql/var/ecs-hb-hb1.pid).  [FAILED]

起初,在网上搜着两条信息,看了很多个解决方案,都没解决到问题。

后来,查看日志目录下的*.err错误日志文件,有如下日志信息:

161106 20:18:10 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
2016-11-06 20:18:11 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.29-log) starting as process 24480 ...
2016-11-06 20:18:11 24480 [Note] Plugin 'FEDERATED' is disabled.
2016-11-06 20:18:11 24480 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-11-06 20:18:11 24480 [Note] InnoDB: The InnoDB memory heap is disabled
2016-11-06 20:18:11 24480 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-11-06 20:18:11 24480 [Note] InnoDB: Memory barrier is not used
2016-11-06 20:18:11 24480 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-11-06 20:18:11 24480 [Note] InnoDB: Using CPU crc32 instructions
2016-11-06 20:18:11 24480 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2016-11-06 20:18:11 24480 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2016-11-06 20:18:11 24480 [ERROR] Plugin 'InnoDB' init function returned error.
2016-11-06 20:18:11 24480 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-11-06 20:18:11 24480 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-11-06 20:18:11 24480 [ERROR] Aborting

2016-11-06 20:18:11 24480 [Note] Binlog end
2016-11-06 20:18:11 24480 [Note] Shutting down plugin 'partition'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_METRICS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMPMEM'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_CMP'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'INNODB_TRX'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'ARCHIVE'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'BLACKHOLE'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'MyISAM'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'MRG_MYISAM'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'CSV'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'MEMORY'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'sha256_password'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'mysql_old_password'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'mysql_native_password'
2016-11-06 20:20:39 25073 [Note] Shutting down plugin 'binlog'
2016-11-06 20:20:39 25073 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

161106 20:20:39 mysqld_safe mysqld from pid file /usr/local/mysql/var/ecs-hb-hb1.pid ended

经筛选出的重要错误提示为下面几行:

2016-11-06 20:18:11 24480 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2016-11-06 20:18:11 24480 [ERROR] InnoDB: Cannot allocate memory for the buffer pool

在网上搜索查询相关信息,经得知为内存不足,/etc/my.cnf配置文件中的innodb_buffer_pool_size配置项值过大导致。修改小点后,就能正常启动。

最后,得出的教训是,MySQL部分配置非常重要,一定要根据实际情况进行配置,否则会出现意想不到的问题出现。