Sunday, July 6, 2014

Enable Remote Access To Mysql Database Server Or On VPS Ubuntu

If you want to make application with remote database, you will need to grant database on your server to be accessed by your application. Now I will tell you how to grant access so your application can use mysql from your server.

Install mysql server first
sudo apt-get install -y mysql-server
if nano is not installed, install it
"sudo apt-get install -y nano"
Open mysql configuration with nano
"nano /etc/mysql/my.cnf"
Look for bind-address=127.0.0.1 and change 127.0.0.1 with your IP Server, for example your IP Server is 1.1.1.1
bind-address = 1.1.1.1
Restart your mysql service
"service mysql restart"
Set your iptables to accept connection from port 3306
"/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT"
Save your iptables configuration
"/sbin/iptabes-save"
Login to your mysql
"mysql -u root -pYourPassword"  <-- No space between -p and Your Password
Create your database, for example RemoteDatabase
create database RemoteDatabase;
 Add a mysql user and grant to access your database
 GRANT ALL ON RemoteDatabase.* TO UserName@`%` IDENTIFIED BY  'YourAnotherPassword';
To check if you can connect to your database, do this from your client computer
mysql -u UserName -h 1.1.1.1 -p
And finally input your another password.

Tested on Ubuntu Server 12.04

Source 1 (Indonesian Only)
Source 2

0 comments:

Post a Comment