Can't run migrations in Google Cloud SQL
Asked Answered
R

3

6

I'm using Laravel 5.3, and following this tutorial to get myself set up with Google Cloud:

https://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard

I'm at the part where I'm trying to run my database migrations, so I do:

export DB_DATABASE=db DB_USERNAME=root DB_PASSWORD=<my_db_password> DB_SOCKET="<my_connection_name>"
php artisan migrate --force

But I get the following output in my terminal:

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform
ation_schema.tables where table_schema = db and table_name = migrations)

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] No such file or directory

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

If I try to connect to the server through MySQL Workbench, it connects fine.

Here is my app.yaml file (I removed sensitive information):

runtime: php72

runtime_config:
    document_root: public

env_variables:
    APP_LOG: errorlog
    # Application key
    APP_KEY: <my_app_key>
    # Storage path
    APP_STORAGE: /tmp
    VIEW_COMPILED_PATH: /tmp
    CACHE_DRIVER: database
    SESSION_DRIVER: database
    # Database configuration
    DB_CONNECTION: mysql
    DB_SOCKET: /cloudsql/<my_connection_name>
    DB_HOST: 127.0.0.1
    DB_PORT: 3306
    DB_DATABASE: db
    DB_USERNAME: root
    DB_PASSWORD: <my_db_password>

beta_settings:
    cloud_sql_instances: "<my_connection_name>"

I also tried changing 127.0.0.1 to localhost, but I get the same error.

What am I doing wrong??

Ramekin answered 4/7, 2020 at 17:41 Comment(6)
Does this answer your question? PHP Connection failed: SQLSTATE[HY000] [2002] Connection refusedFootlambert
No, it does notRamekin
Bump? Help me pleaseRamekin
Did you find any solution?Elderly
Not yet, unfortunately @ElderlyRamekin
Bumping this againRamekin
P
0

Try to connect to database without DB_SOCKET option. The error message indicates that a MySQL connection via socket is tried (which is not supported).

Popcorn answered 15/12, 2020 at 12:1 Comment(0)
C
0

Use Below app.yaml configurations

runtime: php
env: flex

runtime_config:
  document_root: public

# Ensure we skip ".env", which is only for local development
skip_files:
  - .env
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10
env_variables:
# Put production environment variables here.
 APP_LOG: errorlog
 APP_KEY: key
 CACHE_DRIVER: database
 SESSION_DRIVER: database
 ## Set these environment variables according to your CloudSQL 
 configuration.
 DB_HOST: localhost
 DB_DATABASE: dbname
 DB_USERNAME: username
 DB_PASSWORD: db_password
 DB_SOCKET: "/cloudsql/connection_name"

beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
# e.g. "project:region:cloudsql-instance"
cloud_sql_instances: "connection_name"
Cheapskate answered 15/12, 2020 at 18:3 Comment(0)
F
-1

Do not include DB_HOST on the environment variables for MySQL connections, as indicated in step 4 of Set up Database Sessions

The reason behind that is working on your machine with 127.0.0.1 is because you might have MySQL installed on your machine and it is connecting there.

Francenefrances answered 6/7, 2020 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.