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.