0

Is there anyway to open a port 3306 between MySQL database running on compute engine in google cloud (not cloud SQL) and MySQL workbench running on your local machine to connect ?

I was able to connect it by opening port 3306 on all networks (0.0.0.0/0) under firewall rules. However, I want to restrict it to connect to my laptop only, not all networks. I have a dynamic IP address but I won't mind creating firewall rule every time I connect. Please advise.

1

I researched alot, I guess there is no way to allow your laptop dhcp address at googlecloud firewall. I was able to fix this hurdle by ceating ssh tunnel

Windows Source: http://quintagroup.com/services/support/tutorials/mysql-windows

Linux Source: http://quintagroup.com/services/support/tutorials/mysql-linux

1

Yes, you can create a GCE firewall rule for tcp:3306 protocol/port and specify your remote IP address as source IP range under Source filter of the rule. This will allow access to your MySQL service running on GCE VM only from your IP address.

Since your IP address is a dynamic one, you can use the following gcloud command to update the source IP address on firewall rule, whenever your IP address is changed:

gcloud compute firewall-rules update --source-ranges=<Your IP Address/32>

If the IP address of your laptop is changing once it re-connects to Internet, you may use Task Scheduler of Windows OS to run the gcloud command automatically after new internet connection established.

Also, check this link to find out how you can get your public IP address through a command. This will be useful if your computer is connected to a private network and ipconfig command does not display your external IP address.

You can find equivalent commands for Linux OS as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.