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 (127.0.0.1). 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 0.0.0.0

bind-address=<YOUR-SERVER-IP>

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

GRANT ALL ON *.* TO <user_name>@'%' IDENTIFIED BY '<PASSWORD>';

where

 *.* -> 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 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Google Compute Engine

Delete project from Google Developer Console

Delete Compute Engine Instances Login with gmail id where instances are located. https://console.cloud.google.com/project?authuser=1 Select Project Search for compute engine Select Instance name and click stop and then delete. Deleting DB instances Search for SQL Select Read more…

Linux

Installing and Configuring ProFTPD Server in Ubuntu/Debian

1) Install proftpd using apt-get command $ sudo apt-get update$ sudo apt-get upgrade $ sudo apt-get install proftpd 2) Add this line in /etc/shells file : /bin/false 3) Create a /home/FTP-shared directory : cd /homesudo Read more…

MySQL

SQL_CALC_FOUND_ROWS : Get total records even if limit clause in QUERY

Problem Statement:- There are many situation when we want to restrict the records that a query returns, but we want the total records that query had matched.Like, If we use LIMIT clause in the query Read more…