Cloud SQL for MySQL

in side7python •  4 years ago 

試せてないけどメモ

Cloud SQL インスタンスの設定
https://cloud.google.com/sql/docs/mysql/connect-app-engine?hl=ja


コネクタの作成
https://cloud.google.com/vpc/docs/configure-serverless-vpc-access?hl=ja


https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/cloudsql
pythonコーディング

The SQLAlchemy engine will help manage interactions, including automatically

# managing a pool of connections to your database
db = sqlalchemy.create_engine(
    # Equivalent URL:
    # mysql+pymysql://<db_user>:<db_pass>@/<db_name>?unix_socket=/cloudsql/<cloud_sql_instance_name>
    sqlalchemy.engine.url.URL(
        drivername="mysql+pymysql",
        username=db_user,
        password=db_pass,
        database=db_name,
        query={"unix_socket": "/cloudsql/{}".format(cloud_sql_connection_name)},
    ),
    # ... Specify additional properties here.
    # ...
)


VPC ネットワークへの接続
https://cloud.google.com/appengine/docs/standard/python/connecting-vpc?hl=ja

サービスの app.yaml ファイルに vpc_access_connector セクションを追加します。


vpc_access_connector:
name: "projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME"


サービスをデプロイします。
gcloud app deploy

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!