Closed9

fly.ioでMySQLを動かす

shuntakashuntaka

バックエンドNestとMySQLそれぞれのインスタンスで通信できればいいんだけど、マイグレーション周りとか結構厳しそう

shuntakashuntaka

金払え言われた

$ fly volumes create mysqldata --size 10
Update available 0.0.465 -> 0.0.469.
Run "fly version update" to upgrade.
Some regions require a paid plan (fra, maa).
See https://fly.io/plans to set up a plan.

? Select region: Tokyo, Japan (nrt)
Error failed creating volume: To create more than 1GB in volumes please add a payment method. https://fly.io/dashboard/shuntaka9576/billing

shuntakashuntaka

クレカ登録したら、Hobbyプランになって、うまくいった。
紛らわしいけどcreate datadataはボリューム識別子。任意の名前をつけるのが良い。

$ fly volumes create data --size 10
Update available 0.0.465 -> 0.0.469.
Run "fly version update" to upgrade.
Some regions require a paid plan (fra, maa).
See https://fly.io/plans to set up a plan.

? Select region: Tokyo, Japan (nrt)
        ID: hoge
      Name: data
       App: hoge-db
    Region: nrt
      Zone: f5da
   Size GB: 10
 Encrypted: true
Created at: 25 Feb 23 08:45 UTC

fly secrets set MYSQL_PASSWORD=password MYSQL_ROOT_PASSWORD=password

この後は基本ドキュメントの通り

fly deployでデプロイすると、突然の死(OOM killed!)。なのでこのステップを一旦飛ばしてメモリ調整をとfly.tomlの修正をした後、実行がいいです。

$ fly deploy
(中略)

2023-02-25T08:50:33Z   [info]Starting clean up.
2023-02-25T08:50:33Z   [info]Umounting /dev/vdc from /data
2023-02-25T08:50:33Z   [info]Process appears to have been OOM killed!
--> v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

ドキュメントの通りメモリを調整

fly scale memory 2048

fly.toml側もドキュメントの通り修正

 [experimental]
   cmd = [
-    "--default-authentication-plugin",
-    "mysql_native_password",
-    "--datadir",
-    "/data/mysql"
+    "--default-authentication-plugin", "mysql_native_password",
+    "--datadir", "/data/mysql",
+    "--performance-schema=OFF",
+    "--innodb-buffer-pool-size", "64M"
   ]
shuntakashuntaka
flyctl proxy 13306:3306 -a <アプリ名>

ぐぬぬ、、ちなみに127.0.0.1にすれば--protocolオプションは不要

$ mysql -h localhost -P 13306 -u non_root_user some_db --protocol tcp
ERROR 1130 (HY000): Host 'IPv6アドレス' is not allowed to connect to this MySQL server

全部作り直したらいけた!(もしかしたらパスワードを引数で指定してなかったからかも

$ mysql -h localhost -P 13306 -u non_root_user some_db -ppassword --protocol tcp
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
このスクラップは2023/02/25にクローズされました