0
votes

I made instance in Google Cloud > Storage > SQL > MYSQL. Now I have to import database in it so I am trying to connect to MYSQL

using adminer, but it gives following error

SQLSTATE[HY000] [2002] Operation timed out

I also tried via HeidiSQL > MariaDB or MYSQL (SSL Tunnel) but here also it does not connect and gives error

https://prnt.sc/o58in0

I am mentioning

Host: Public Ip of SQL instance

Username: root

Any suggestions, what could be the fix?

1

1 Answers

2
votes

Your error typically means that a firewall blocked your connection attempt.

For Cloud SQL, this typically means that you have not enabled instance-level access.

Since your error is 10060, which is a Windows WinSock error message, I am assuming that you are running on Windows. The steps are similar for Linux.

There are two methods to enable access to Cloud SQL:

Cloud SQL Proxy

This is the recommended method and is secure. Download and install the Cloud SQL Proxy to your the computer that you want to connect from. If you have set up the Cloud SDK (gcloud), Cloud SQL Proxy will use your Cloud SDK credentials. If not, then you will need to create and download a service account with (usually) the Cloud SQL Client role.

You will need the "instance connection name" from Cloud SQL Instance details page.

  • Download Cloud SQL Proxy (link) to your computer. Remember the full path to the program. Save the program as "cloud_sql_proxy.exe"
  • Start the Cloud SQL Proxy

[full_path_to_program]\cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306

OR

[full_path_to_program]\cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306 -credential_file=[PATH_TO_KEY_FILE]
  • Connect using mysql.exe: `mysql -u USERNAME -p --host 127.0.0.1

Public IP Method

The second method is not secure unless you also enable SSL, which I will not cover in this answer. I do not recommend this method except for knowledgeable persons.

  • Figure out what your public IP address is. Go to any website such as "MXToolbox" https://mxtoolbox.com/whatismyip/

  • Go to the Google Cloud Console

  • Go to the Cloud SQL Instances Details page
  • Select the Connections tab
  • Click Add network
  • In the Network field, enter your Public IP address using CIDR notice: eg 145.11.22.33/32
  • Enter a name such as "My Home IP"
  • Click Done
  • Click Save

Note: Most home Internet services change your Public IP address periodically. This means that you will need to update your Public IP address in Cloud SQL if you are using the second method.