MySQL自动停机的问题处理实战记录
最近帮别人做的一个项目机器上面跑MySQL老是隔一段时间就自动停了。刚开始以为是以外停止,也没注意,就手动再启动。可是过了没两天又停止了。
后来仔细查了查mysqld的日志:
2020-05-27T10:15:12.569342Z0[System][MY-010116][Server]/usr/libexec/mysqld(mysqld8.0.17)startingasprocess19493
2020-05-27T10:15:14.448256Z0[System][MY-010229][Server]Startingcrashrecovery...
2020-05-27T10:15:14.475411Z0[System][MY-010232][Server]Crashrecoveryfinished.
2020-05-27T10:15:14.691345Z0[Warning][MY-010068][Server]CAcertificateca.pemisselfsigned.
2020-05-27T10:15:15.677386Z0[System][MY-010931][Server]/usr/libexec/mysqld:readyforconnections.Version:'8.0.17' socket:'/var/lib/mysql/mysql.sock' port:3306 Sourcedistribution.
2020-05-27T10:15:15.951210Z0[System][MY-011323][Server]XPluginreadyforconnections.Socket:'/var/lib/mysql/mysqlx.sock'bind-address:'::'port:33060
2020-05-27T11:26:19.955004Z0[System][MY-010116][Server]/usr/libexec/mysqld(mysqld8.0.17)startingasprocess19757
2020-05-27T11:26:20.181302Z0[ERROR][MY-012681][InnoDB]mmap(137363456bytes)failed;errno12
2020-05-27T11:26:20.181360Z1[ERROR][MY-012956][InnoDB]Cannotallocatememoryforthebufferpool
2020-05-27T11:26:20.181379Z1[ERROR][MY-012930][InnoDB]PlugininitializationabortedwitherrorGenericerror.
2020-05-27T11:26:20.181401Z1[ERROR][MY-010334][Server]FailedtoinitializeDDStorageEngine
2020-05-27T11:26:20.181543Z0[ERROR][MY-010020][Server]DataDictionaryinitializationfailed.
2020-05-27T11:26:20.183642Z0[ERROR][MY-010119][Server]Aborting
2020-05-27T11:26:20.184163Z0[System][MY-010910][Server]/usr/libexec/mysqld:Shutdowncomplete(mysqld8.0.17) Sourcedistribution.
上面显示是Cannotallocatememoryforthebufferpool,无法分配内存给缓存池。马上想到是内存不足,这台机器是1GB的内存,还跑着Nginx和PHP-FPM。
使用top看了看mysqld占用的内存达到了48%。内存占用还是蛮高的。
当然了升级机器配置是比较好的办法,但是毕竟经费有限。所以我们先给它加个swap交换空间:
ddif=/dev/zeroof=/swapfilebs=1Mcount=2048 mkswap/swapfile swapon/swapfile systemctlrestartmysqld
上面我们加了2GB的交换空间给机器。然后重启mysqld。再使用top看了看,发现交换空间渐渐被使用了。
睡了一觉起来一看,mysqld服务没有再自动停止,内存占用已经下降到22%,看了看错误日志,也是空的。
嗯,看来还不错嘛。再观察个几天看看,没问题的话应该就好了