近日使用mysql時遇到了一個問題,就是mysql一直無法正常啟動,經過多次嘗試,依然重啟不了。通過排查,最終找到了問題所在。
Error log: 2021-10-25T07:22:47.267770Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.32) starting as process 20747 ... 2021-10-25T07:22:47.269956Z 0 [Note] InnoDB: PUNCH HOLE support available 2021-10-25T07:22:47.269976Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2021-10-25T07:22:47.269984Z 0 [Note] InnoDB: Uses event mutexes 2021-10-25T07:22:47.269988Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2021-10-25T07:22:47.269991Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2021-10-25T07:22:47.269993Z 0 [Note] InnoDB: Using Linux native AIO 2021-10-25T07:22:47.270071Z 0 [Note] InnoDB: Number of pools: 1 2021-10-25T07:22:47.270114Z 0 [Note] InnoDB: Using CPU crc32 instructions 2021-10-25T07:22:47.271128Z 0 [ERROR] InnoDB: mmap(137458688 bytes) failed; errno 12 2021-10-25T07:22:47.271150Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool 2021-10-25T07:22:47.271154Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error 2021-10-25T07:22:47.271157Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2021-10-25T07:22:47.271159Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2021-10-25T07:22:47.271162Z 0 [ERROR] Failed to initialize plugins. 2021-10-25T07:22:47.271165Z 0 [ERROR] Aborting mysql啟動失敗原因為InnoDB的buffer pool無法分配足夠內存,導致執行初始化步驟失敗。
解決方法:
在/etc/mysql/my.cnf文件中,進行如下修改:
#innodb_buffer_pool_size = 1G innodb_buffer_pool_size = 128M
將innodb_buffer_pool_size的原先值進行縮小,重新啟動mysql,此時mysql已可以正常啟動。
通過以上操作,成功解決了mysql啟動失敗的問題,同時注意到InnoDB的buffer pool預分配內存的值應該按照實際情況進行調整。