stephen
stephen

Reputation: 385

gcloud can't access cloud sql

I can list the databases in my Cloud SQL instance but I can't connect to it.

gcloud beta sql databases list --instance=dbinstance  
NAME                CHARSET  COLLATION  
information_schema  utf8     utf8_general_ci  
main                utf8     utf8_general_ci  
mysql               utf8     utf8_general_ci  
performance_schema  utf8     utf8_general_ci  

It is adding my local machine to the authorisation list. I can see that via the console. But it's failing to connect:

gcloud beta sql connect dbinstance --user=root  
Whitelisting your IP for incoming connection for 5 minutes...  
Connecting to database with SQL user [root].  
Enter password:   
ERROR 2003 (HY000): Can't connect to MySQL server on '{db ip}' (110)

It isn't configured to use SSL.

Upvotes: 1

Views: 4240

Answers (1)

ingernet
ingernet

Reputation: 1524

Some thoughts:

A. User root might not be authorized on the database instance, period.

  1. Go to https://console.cloud.google.com/sql/instances/dbinstance/users
  2. Is the user root listed there?
  3. If so, is root authorized from any IP address? (represented by '%')

B. If user root is indeed authorized on 'dbinstance' from any host, there may be a firewall issue in play here on your local network.

  1. In your project, open up the Cloud Shell by clicking on the icon that looks like >_, in the top nav of the Console site. That allows you to move within the GCP network rather than through any firewalls your local network might have in place.
  2. In the Cloud Shell, type: gcloud beta sql connect dbinstance --user=root
  3. It should ask for your password. Type it in.

If the password for root doesn't work, even in the Cloud Shell, try resetting the password (Users tab on your dbinstance Console page, three dots next to root's entry, choose "Change Password."

If the password for root does work within the Cloud Shell environment, you've established that the issue lies between your local machine and the DB instance. Most often it's a firewall issue.

Upvotes: 2

Related Questions