如何将 Strapi (GAE) 应用程序连接到 MySQL (GSC) 数据库?



已编辑:下面的配置现在可以正常工作了!

Package.json: dependencies (部分(:

...
"knex": "latest",
"lodash": "^4.17.5",
"mysql": "^2.17.1",
"sqlite3": "^4.1.0",
"strapi": "3.0.0-beta.15",
"strapi-admin": "3.0.0-beta.15",
"strapi-hook-bookshelf": "3.0.0-beta.15",
"strapi-hook-knex": "3.0.0-beta.15",
....

database.json (staging(

{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-hook-bookshelf",
"settings": {
"client": "mysql",
"host": "${process.env.MYSQL_HOST || '127.0.0.1'}",
"port": "${process.env.MYSQL_PORT || '3306'}",
"database": "${process.env.MYSQL_DATABASE}",
"username": "${process.env.MYSQL_USERNAME}",
"password": "${process.env.MYSQL_PASSWORD}",
"socketPath": "/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}"
},
"options": {
}
}
}
}

app.staging.yaml

runtime: nodejs10
service: strapi
env_variables:
NODE_ENV: staging
MYSQL_USERNAME: <hidden>
MYSQL_PASSWORD: <hidden>
MYSQL_DATABASE: strapi
# e.g. my-awesome-project:us-central1:my-cloud-sql-instance
INSTANCE_CONNECTION_NAME: <hidden>:europe-west1:mysql"
beta_settings:
# The connection name of your instance, available by using
# 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
# the Instance details page in the Google Cloud Platform Console.
cloud_sql_instances: "<hidden>:europe-west1:mysql"

然后,我可以通过运行以下命令成功部署上述设置:

gcloud app deploy app.staging.yaml --project <hidden> --quiet

在错误的第一行中,您将看到:

错误:ER_ACCESS_DENIED_ERROR:拒绝访问用户"未定义"@'cloudsqlproxy~\(使用密码:是(

所以看起来process.env.MYSQL_USERNAME是不确定的。确保在app.yaml中正确设置环境变量。

相关内容

  • 没有找到相关文章

最新更新