Wednesday 21 February 2018

thumbnail

Mysql database creation for Remotely accessing database

Introduction

In this tutorial we are going to see how to create mysql database for local use and how to configure it for remotely accessing the database.

For this tutorial I have taken AWS-EC2 Instance and configured the security group to allow the inbound connection for mysql database from remote IP.

You can add the particular IP or allow everyone to connect to it. But for the security reason you should allow only specific IP from where you want to access database.

I have taken Ubuntu EC2 instance for this demo. You can take of your choice.

1. First of all update and upgrade your Instance like below :- 

sudo apt-get update
sudo apt-get upgrade

2. Install the mysql-server on your instance :-

sudo apt-get install mysql-server -y

3. Configure the mysqld.cnf like below :-

Change the bind address from 127.0.0.1 to 0.0.0.0 like below 

cd /etc/mysql/mysql.conf.d/
vim mysqld.cnf

bind-address = 0.0.0.0

save and exit the file 

4. Restart the mysql service to take effect :-

sudo service mysql restart

5. Create the database for remotely accessing the database :-

The only difference is you will have to keep in mind that you have to assign remote location ip from where you will access the database. 

CREATE DATABASE testing1;
CREATE USER 'testing1'@'20.13.11.10' IDENTIFIED BY 'testing1';
GRANT ALL PRIVILEGES ON testing1.* TO 'testing1'@'20.13.11.10';
FLUSH PRIVILEGES;

For locally accessing the database you can define localhost instead of IP address. 

To allow anyone create database like below :-

CREATE DATABASE wordpress;
CREATE USER 'wordpress'@'%' IDENTIFIED BY 'wordpress';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%';
FLUSH PRIVILEGES;

Here % mean anyone can connect to database.

That's it guys
Please do Comments, Likes and Share.   

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments