最近幫別人做的一個項目機器上面跑MySQL老是隔一段時間就自動停了。剛開始以為是以外停止,也沒注意,就手動再啟動??墒沁^了沒兩天又停止了。
后來仔細查了查mysqld的日志:
2020-05-27T10:15:12.569342Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.17) starting as process 19493
2020-05-27T10:15:14.448256Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2020-05-27T10:15:14.475411Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2020-05-27T10:15:14.691345Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-05-27T10:15:15.677386Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.17' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution.
2020-05-27T10:15:15.951210Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/lib/mysql/mysqlx.sock' bind-address: '::' port: 33060
2020-05-27T11:26:19.955004Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.17) starting as process 19757
2020-05-27T11:26:20.181302Z 0 [ERROR] [MY-012681] [InnoDB] mmap(137363456 bytes) failed; errno 12
2020-05-27T11:26:20.181360Z 1 [ERROR] [MY-012956] [InnoDB] Cannot allocate memory for the buffer pool
2020-05-27T11:26:20.181379Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2020-05-27T11:26:20.181401Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2020-05-27T11:26:20.181543Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2020-05-27T11:26:20.183642Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-05-27T11:26:20.184163Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.17) Source distribution.
上面顯示是Cannot allocate memory for the buffer pool
,無法分配內存給緩存池。馬上想到是內存不足,這臺機器是1GB的內存,還跑著 Nginx 和 PHP-FPM 。
使用 top 看了看 mysqld 占用的內存達到了48% 。內存占用還是蠻高的。
當然了升級機器配置是比較好的辦法,但是畢竟經費有限。所以我們先給它加個swap交換空間:
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap /swapfile
swapon /swapfile
systemctl restart mysqld
上面我們加了2GB的交換空間給機器。然后重啟 mysqld。再使用top看了看,發(fā)現(xiàn)交換空間漸漸被使用了。
睡了一覺起來一看,mysqld服務沒有再自動停止,內存占用已經下降到22%,看了看錯誤日志,也是空的。
嗯,看來還不錯嘛。再觀察個幾天看看,沒問題的話應該就好了😎😎😎。
好了,到此這篇關于MySQL自動停機的問題處理的文章就介紹到這了,更多相關MySQL自動停機處理內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- mysql自動停止 Plugin FEDERATED is disabled 的完美解決方法
- MySQL服務自動停止的解決方法
- MySQL不停地自動重啟的解決方法