t2.microからt2.nanoにしたらmysqldが起動しなかったメモ

現象

$ sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

mysqld.log

2020-11-13T06:18:39.804582Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 11077
2020-11-13T06:18:39.836009Z 0 [Warning] [MY-010122] [Server] One can only use the --user switch if running as root
2020-11-13T06:18:39.926149Z 0 [ERROR] [MY-012681] [InnoDB] mmap(137363456 bytes) failed; errno 12
2020-11-13T06:18:39.926193Z 1 [ERROR] [MY-012956] [InnoDB] Cannot allocate memory for the buffer pool
2020-11-13T06:18:39.926220Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2020-11-13T06:18:39.926240Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2020-11-13T06:18:39.926337Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2020-11-13T06:18:39.928100Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-11-13T06:18:39.933309Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.17)  MySQL Community Server - GPL.

swap領域がない

$ free
              total        used        free      shared  buff/cache   available
Mem:         491212       74336      246564         532      170312      383356
Swap:             0           0           0

swap領域を作る

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 14.8229 s, 72.4 MB/s

$ sudo mkswap /swapfile
mkswap: /swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=*******************

$ sudo swapon /swapfile
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
$ sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service

$ sudo service mysqld status
Redirecting to /bin/systemctl status mysqld.service
~
   Active: active (running) since Fri 2020-11-13 15:22:10 JST; 6min ago

解決

参考

qiita.com