Google Cloud SQLのセットアップ
- https://cloud.google.com/python/getting-started/using-cloud-sql?hl=ja
- https://cloud.google.com/sql/docs/mysql/create-manage-users?hl=ja
RDBはMySQLを使う.
cloud sql instanceの詳細を取得
gcloud sql instances describe cnfbox-dev-store
Cloud SQL Proxyでつなぎこみ
[koya-mac:~]$ ./cloud_sql_proxy -instances="cnfbox-dev:us-central1:cnfbox-dev-store"=tcp:3306
2020/01/07 13:48:02 Rlimits for file descriptors set to {&{8500 9223372036854775807}}
2020/01/07 13:48:03 Listening on 127.0.0.1:3306 for cnfbox-dev:us-central1:cnfbox-dev-store
2020/01/07 13:48:03 Ready for new connections
なぜか,だめなので諦め
gcloudコマンドから操作
データベース作成
[koya-mac:~]$ gcloud sql databases create dev1 --instance="cnfbox-dev-store"
Creating Cloud SQL database...done.
Created database [dev1].
instance: cnfbox-dev-store
name: dev1
project: cnfbox-dev
データベース確認
[koya-mac:~]$ gcloud sql databases list --instance=cnfbox-dev-store
NAME CHARSET COLLATION
information_schema utf8 utf8_general_ci
dev1 utf8 utf8_general_ci
mysql utf8 utf8_general_ci
performance_schema utf8 utf8_general_ci
sys utf8 utf8_general_ci
rootパスワード変更
gcloud sql users set-password root --host=% --instance=cnfbox-dev-store --prompt-for-password
ユーザ追加
gcloud sql users create dev1-user --host=% --instance=cnfbox-dev-store --password=[PASSWORD]
mysql db へ接続
mysql -u root -h 34.66.32.43 -p
terminalでの操作:
create table config (
id INT PRIMARY KEY AUTO_INCREMENT,
content json DEFAULT NULL
);
- db-name: dev2, dev1
- table-name: config