I am trying to connect to cloud sql from cloud run. However, I am getting the error, not sure what needs to be done. Code def create_database_connection(db_user, db_pass, db_name, instance_connection_name): db_socket_dir = os.environ.get("DB_SOCKET_DIR", "/cloudsql") pool = sqlalchemy.create_engine( 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>" } ), ) return pool @app.route('/test', methods=['GET']) def handle_test(): connection = database.create_database_connection(db_user=os.getenv("db_user"), db_pass=os.getenv("db_pass"), db_name=os.getenv("db_name"), instance_connection_name=os.getenv("instance_connection_name")) Session = sessionmaker(bind=connection) session = Session() records = session.query(Demo).all() records_list = [record.__dict__ for record in records] for record in records_list: del record["_sa_instance_state"] print(records_list) json_string = json.dumps(records_list) return json_string Error Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 602, in connect sock.connect(self.unix_socket) FileNotFoundError: [Errno 2] No such file or directory in connect raise exc sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)") I am using gcloud run to deploy the app directly from source code. So image is being build and deployed by google cloud build. I tried creating folder as well, in docker file however still getting same error. Dockerfile FROM python:3.10-slim ENV PYTHONUNBUFFERED True ENV APP_HOME /app WORKDIR $APP_HOME COPY . ./ RUN mkdir -p /cloudsql RUN pip install --no-cache-dir -r requirements.txt CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app Update: I can see folder /cloudsql being created I changed the DB_SOCKER_DIR to /tmp and still the same issue. I have no issue connecting to same database with same code through cloud function. I am getting error only with cloud run I am using following command to deploy cloud run gcloud run deploy processcontrol --source . --set-cloudsql-instances=cloud-sql-8 I have connection set for the SQL I am trying to access. Continue reading...