Access MySQL through public IP of VM instance (Hosted on Google Server)
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 :)
‘%’ -> 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 :)
No comments:
Post a Comment