# Remember - storing secrets in plaintext is potentially unsafe. Consider using# something like https://cloud.google.com/secret-manager/docs/overview to help keep# secrets secret.db_user=os.environ["DB_USER"]db_pass=os.environ["DB_PASS"]db_name=os.environ["DB_NAME"]db_socket_dir=os.environ.get("DB_SOCKET_DIR","/cloudsql")instance_connection_name=os.environ["INSTANCE_CONNECTION_NAME"]pool=sqlalchemy.create_engine(# Equivalent URL:# mysql+pymysql://<db_user>:<db_pass>@/<db_name>?unix_socket=<socket_path>/<cloud_sql_instance_name>sqlalchemy.engine.url.URL.create(drivername="mysql+pymysql",username=db_user,# e.g. "my-database-user"password=db_pass,# e.g. "my-database-password"database=db_name,# e.g. "my-database-name"query={"unix_socket":"{}/{}".format(db_socket_dir,# e.g. "/cloudsql"instance_connection_name)# i.e "<PROJECT-NAME>:<INSTANCE-REGION>:<INSTANCE-NAME>"}),**db_config)
次のステップ
他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[],[]]