Topology: Master-Slave
Type: Standard Asynchronous Replicaiton
This Tutorial assumes that:
1. You have user with sudo privileges
2. and have MySQL DB server is installed in Linux OS on both the hosts. If you dont have it installed please follow our MySQL installation tutorial to install it first
3. You have two Linux Servers with Public IP assigned, one for Master and the other for slave.

Follow below steps on Master Host

sudo vi /etc/mysql/my.cnf

And make below changes:
The first step is to add or edit below entry in the my.cnf file that is used for binding the server to the localhost:
bind-address            = 127.0.0.1
#Replace the standard IP address with the IP address of server.
to
bind-address            = 5.64.456.59 

The next configuration refers to the server-id, in the [mysqld] section. We can choose any number for this (it may just be easier to start with 1), but the number must be unique and must not match any other server-id in your replication group. I’m going to call it one 1. Make sure this line is uncommented.
server-id               = 1

Go to log_bin line. This is where the details of the replication are kept. The slave is going to copy all the changes which are registered in the log. In this step we need to uncomment the line that refers to log_bin:
log_bin                 = /var/log/mysql/mysql-bin.log

Finally, we need to designate the database that will be replicated on the slave server. You can include more than one database by repeating this line for all of the databases you will need.
binlog_do_db            = mydatabase
After you make all of the changes, save and exit out of the configuration file.
Refresh MySQL.
sudo service mysql restart
The next steps will take place in the MySQL shell, itself.
Open up the MySQL shell.
mysql -u root -p
Now we need to create a DB user for replication and grant privileges to the slave DB. You can use this line to name your slave and set up their password. The command should be in this format:
CREATE USER 'slaveuser'@'%' identified by 'Password';

GRANT REPLICATION SLAVE ON *.* TO 'slaveuser'@'%' IDENTIFIED BY 'Password';
Follow up with:
FLUSH PRIVILEGES;
Next to achieve the purpose you will need to open a new window or tab in addition to the one that you are already using a few steps down the line.
In your current tab switch to “mydatabase”.
USE mydatabase;
Following that, lock the database to prevent any new changes:
FLUSH TABLES WITH READ LOCK;
Then type in SHOW MASTER STATUS; and see the output is like:

mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |     102  | mydatabase   |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
This is the position from which the slave database will start replicating. Record these numbers to use later.
If you make any new change in the same window, the database will automatically unlock. For this reason, you should open the new tab or window and continue with the next steps there.
Proceeding with the database still locked, export your database using mysqldump in the new window (Type the below command to export in the bash shell, not in MySQL).
mysqldump -u root -p --opt mydatabase > mydatabase.sql
Now, returning to your your original window, unlock the databases (making them writeable again). Finish up by exiting the shell.
UNLOCK TABLES;
QUIT;
Now you are all done with the configuration of the the master database.

Follow below steps on Slave Host

Configure the Slave Database
Once you have configured the master database. You can now begin to configure the slave database.
Log into your slave server, open up the MySQL shell and create the new database that you will be replicating from the master (then exit):
CREATE DATABASE mydatabase;
EXIT;
Import the database that you previously exported from the master database.
Type below command on bash shell and not on mysql prompt:
mysql -u root -p mydatabase < /path/to/mydatabase.sql
Now we need to update the slave configuration file in the same way as we did the master:
sudo vi /etc/mysql/my.cnf
We have a few things to set up in this configuration. The first is the server-id. This number, as mentioned before needs to be unique. Since on Master it is set on the default (1), be sure to change it’s something different here on slave server.
server-id               = 2
Following that, make sure that your have the following three criteria appropriately filled out:

relay-log               = /var/log/mysql/mysql-relay-bin.log
log_bin                 = /var/log/mysql/mysql-bin.log
binlog_do_db            = mydatabase
We need to add in the relay-log line which is not there by default. Once we have made all of the necessary changes in my.cnf, save and exit out of the slave configuration file.
Restart MySQL once again:
sudo service mysql restart
The next step is to enable the replication from within the MySQL shell.
Open up the the MySQL shell once again and type in the following details, the values in the below command are from the steps on Master host:
CHANGE MASTER TO MASTER_HOST='5.64.456.59',MASTER_USER='slaveuser', MASTER_PASSWORD='Password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=  102;
This command accomplishes below points at the same time:
  • It designates the current server as the slave of our master server.
  • It provides the server the correct login credentials of replication user
  • it lets the slave server know where to start replicating from, the master log file and log position come from the numbers we wrote down previously.

It completes a master and slave server configuration.
Activate the slave server:
START SLAVE;
You be able to see the details of the slave replication by typing in this command. The \G instead of ; rearranges the text to make it more readable.
SHOW SLAVE STATUS\G
If there is an issue in connecting, you can try starting slave with a command to skip over it as below:
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START; 
Now to check if slave is working fine please follow another tutorial.