If you have MySQL on VM hosted on Google server then by default it listens on the local IP address of the machine that is on localhost ( If you want to access MySQL using public IP of VM then following are some steps :

1) SSH into VM instance.

2) Go to /etc/mysql directory using

cd /etc/mysql

3) Edit my.cnf file. By default, the permissions are u=rw,g=r,o=r so we need to change its permissions to edit using

sudo chmod u=rwx,g=rwx,o=rwx my.cnf

4) Now edit this file using

vi my.cnf 

5) Under [mysqld] directive change bind-address to


6) Comment out the skip-networking

# skip-networking

7) Save my.cnf by pressing Esc and :wq and hit enter

8) Restart the Mysql service using

 etc/init.d/mysqld restart

9) Login to mysql using

mysql -u root -p mysql

10) Grant access to user using



 *.* -> database_name.tables (can provide access to particular database)
‘%’ -> IP_address (provide access to particular ip)

11) You need to open TCP port 3306 using iptables or BSD pf firewall using

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

12) Add firewall rule on Google VM instance

Project Name -> Compute Engine -> Network -> Click on default Network

13) Add firewall Rule like

Provide any name and under Allowed protocols and ports -> tcp:3306;

13) Done 🙂