Search code examples
google-cloud-platformgoogle-cloud-sqlmysql-8.0cloud-sql-proxy

Error while connection cloudsql instance using Cloud SQL Auth proxy


I am trying to connect my CloudSQL(MySQL 8.0) database instance having private ip which in GCP using Automatic IAM database authentication and Cloud SQL Auth proxy Iam getting this error access denied for user when accessing db using Heidisql client

I am providing the steps which I have followed to configure this:-

1.Add this flag to the database instance cloudsql_iam_authentication = on

2.Add an IAM policy binding to a user or service account "Cloud SQL Instance User" , "Cloud SQL Client". This role allows users to authenticate into the cloudsql using their cloud identity.

3.Once the role is granted the next step is to add the user or group to the CloudSql instance as below :- Navigate to ‘Console → SQL → Select Instance → Users → Add user account→ Cloud IAM → Enter email address → Add

  1. Grant database privileges to the IAM user

  2. Connecting to the CloudSQL using IAM Database Authentication First we need to install the latest version Cloud SQL auth proxy binary, then authenticate to the Google Cloud IAM.

        $ gcloud auth login
    
        $ gcloud config set project xyz
    
        $ .\cloud_sql_proxy.exe -enable_iam_login -instances=xyz:us-central1:mysql-iam-test=tcp:3306
    

I am attaching image for reference:-

cloud sdk command

Actual error


Solution

  • To connect to a Cloud SQL instance using Cloud SQL Auth Proxy, you need to use -ip_address_types=PRIVATE flag. You can view more about using the Cloud SQL Auth proxy with private IP here.