我们已经尝试了在Stackoverflow上可以找到的几乎所有解决方案,但仍会收到此错误。
我们在Laravel项目中使用了Google Cloud SQL。我们已将项目部署在App Engine中,并正在使用Cloud SQL进行数据库连接。我们遵循this进行部署,但是在部署之后,我们无法连接数据库并收到错误消息:
SQLSTATE [HY000] [2002]没有这样的文件或目录。
SQLSTATE [HY000] [2002]没有这样的文件或目录(SQL:从
sessions
中选择*,其中id
= dbzqd19nOIbfwWndCLAbNYXThlIge96OM3t9MjDu限制1)
我们可以与公共实例IP建立连接,并且在我们的本地开发中可以正常工作,但是当我们在应用引擎上部署代码时,就会遇到此问题。
App.yaml文件配置:
runtime: php
api_version: '1.0'
env: flexible
threadsafe: true
env_variables:
APP_DEBUG: 'True'
APP_KEY: '<APP KEY HERE>'
APP_LOG: errorlog
APP_NAME: <APP NAME HERE>
beta_settings: None
CACHE_DRIVER: database
cloud_sql_instances: '<project-id-here>:<region-here>:<name here>'
DB_DATABASE: <name here>
DB_HOST: 127.0.0.1 or localhost (neither work)
DB_PASSWORD: <PASSWORD HERE> (also leaving empty doesn't work)
DB_SOCKET: /mysql/mysql.sock
DB_USERNAME: root
SESSION_DRIVER: database
STORAGE_DIR: /tmp
automatic_scaling:
min_num_instances: 2
max_num_instances: 20
cpu_utilization:
target_utilization: 0.5
答案 0 :(得分:1)
问题是unix套接字文件路径当前设置为/mysql/mysql.sock
。从App Engine实例进行连接时,应将其设置为/cloudsql/<INSTANCE_CONNECTION_NAME
。在Cloud SQL文档中查看Connecting from App Engine页面。