Enabling Remote Access to MySql

Hello Temans Temans…. this will remind me.. hehe

by default remote access to the MySQL database server is disabled for security reasons.
However, some time you need to provide remote access to database server from home or a web server.
This post will explain how to setup a user account and access mysql server remotely.

case-nya :

1. gw punya server di 240.125.xxx.xxx yang ada mysql-server database-nya

english: I have a mysql-server on 240.125.xxx.xxx

2. nah gw punya client tapi IP-nya dinamics, di pakenya di android, iOS dll

english: and the clients have dinamics IP-Address, that run on Android, iOS or Desktop App

3. gw mau akses / Query dari manapun. untuk menambah atau menghapus atau apapun pada record-nya

english: I wanna access that database or query from anywhere, for adding, remove record etc.

after, 5 minutes googling and confusing and make my head start to blow, I finally found a simple way to do this.

lets start!!!

Login to your Machine

assume that your machine is a *nix machine, you can do this from any-platform, from windows you can

access remotely by using putty ssh, from linux you can directly using ssh.

$ ssh root@240.125.xxx.xxx

Edit The “my.cnf” mysql Configuration File

you have to edit this file and add your public-IP on the following line :

# vim /etc/mysql/my.cnf

add this :

bind-address    = 240.125.xxx.xxx

and the rest of configuration file, should be look like this :

user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 240.125.xxx.xxx

Save and Close The File

you have to restart the mysql service

# /etc/init.d/mysql restart

Grant Access to Any Remote IP Address

example parameter :

Database  : myDatabase

User           : root

Password : password

remoteIP : ANY

 

connect and login to database :

# mysql -u root -p

enter this command :

# mysql> GRANT ALL ON myDatabase.* TO root@’%’ IDENTIFIED BY ‘password’;

logout from mysql

# mysql> exit

ok, now you can try to access and remotely query or add or whatever you want to your database.

 

Thanks for Reading

Regards

Tommy Agustianto

Advertisements
Enabling Remote Access to MySql

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s