MySQL is very easy to setup and requires minimum of time and resources.
In this tutorial we will setup a simple Master - Slave replication.
We assume that 2 MySQL servers are already installed if not follow this tutorial before you continue MySQL Installation on Linux.
In this example we will use the following servers bih001(10.000.1.189)/Master and bih002(10.000.1.210)/Slave.
Follow the steps that are required to configure the MySQL replication environments.
Step 1: Edit the configuration files & start the MySQL Servers.
Add the following lines to your Master server in our case bih001
When editing the configuration file /etc/mysql/my.cnf and be sure to use different server ids for the hosts
Step 2: Add the following lines to your Slave server in our case bih002.
Make sure the paths are correct.
Step 3:Start your MySQL servers with the new configuration
Step 4:Create Replication User
Create an account on the master server that the slave server can use to connect.
This account must be given the REPLICATION SLAVE privilege.
Step 5:Find the master_log_file & master_log_pos
Now you need to find the master_log_file & master_log_pos that will be used for the Initialize Replication command .
Step 5:Initialize Replication
Connect to the SLAVE server and initiate replication using the following script.
Where:
MASTER_HOST: the IP or host-name of the master server, in this example blue or 10.000.1.189.
MASTER_USER: this is the user we granted the REPLICATION SLAVE privilege to in Step 4.
MASTER_PASSWORD: this is the password we assigned to REPLICATION user in Step 4
MASTER_LOG_FILE: is mysql-bin.000004 (wouldn't be empty if there were existing writes to be picked up from the master)
MASTER_LOG_POS: is 383(would likely be different if there were existing writes to be picked up from the master)
Step 6:Start replication process
Connect to the slave server and issue the following command:
To check the status of the replication you can use the commands:
Also create objects on the master and check if they are created on to the slave server as well.