Replication consists of following 3 parts….
- The master records changes to its data in its binary log (Binary Log Events).
- The slave copies the master’s binary log events to its relay log.
- The slave replays the events in the relay log, applying the changes to its own
data using Slave Thread.
The basic steps to set up replication are…
- Set up replication accounts on master server.
- Configure the master and slave.
- Instruct the slave to connect to and replicate from the master.
Here are few assumptions….
Master IP Address: 192.168.1.215
Slave IP Address: Â 192.168.1.203
Replication User: replication
User Password: slave
The I/O Slave Thread (it runs on Slave Server) makes a TCP/IP connection to the master. Thats why we need to create an user account on Master Server with proper privileges.
Now run the following query on Master to create a Slave account….
mysql>Â GRANT REPLICATION SLAVE ON *.* TO ‘replication‘@’192.168.1.203′ IDENTIFIED BY ’slave’;
Now edit my.cnf file on Master accordingly.
[mysqld]
server-id                      = 1
log-bin                         = mysql-bin
log-bin-index               = mysql-log-bin.index
relay-log                      = mysql-relay-bin
relay-log-index            = mysql-relay-bin.index
expire_logs_days        = 10
max_binlog_size         = 100M
binlog_do_db              = [Database Name to be Replicated]
binlog_ignore_db        = [Database Name not to be Replicated]
#binlog_ignore_db      = [Database Name not to be Replicated] (for more than one data base which is not supposed to be replicated)
datadir                         = /var/lib/mysql
tmpdir                          = /tmp
Now restart Master mysql server and run the following query…
mysql>Â SHOW MASTER STATUS;
Now edit my.cnf file on Slave accordingly…..
[mysqld]
server_id               = 2
master_host           = 192.168.1.215
master_user           = replication
master_password  = slave
master_port           = 3306
relay_log               = mysql-relay-bin
relay-log-index      = mysql-relay-bin.index
We can set the value for master_host, master_user and master_password using mysql query. So it is better to avoid setting those values directly from configuration file.
If master is having data already, insert the data from master server to slave server database or each of the databases.
Copy master database back up inside slave server and run the following command on slave….
mysql -u[username] -p[password] [database name] < directory_path/[database.sql]
Now Restart Mysql Slave server and run following query to synchronize master and slave….
mysql> CHANGE MASTER TO MASTER_HOST=’192.168.1.215′, MASTER_USER=’replication’, MASTER_PASSWORD=’slave’, MASTER_LOG_FILE=’mysql-bin.000004′, MASTER_LOG_POS=570;
Note: MASTER_LOG_FILE and MASTER_LOG_POS values have been taken from the result of SHOW MASTER STATUS
If a Slave is already running on your Slave Server, Mysql Server will throw a error like…
ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first
So run..
mysql> STOP SLAVE;
And run the query for CHANGING MASTER again.
If it shows an error like..
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
Run…
mysql> RESET SLAVE;
And run the query for CHANGING MASTER again.
Finally start slave on slave server using..
mysql> START SLAVE;
mysql> SHOW SLAVE STATUSG
Congrats! Mysql Master-Slave Replication has been set up
Also we will be able to see the Replication Threads in the process list on both the Master and the Slave.
So simply run…
mysql> SHOW PROCESSLIST.


March 13th, 2010 on 8:38 PM
I love this posts . Post more and thanks to all the mistress!
March 17th, 2010 on 8:26 PM
I just think that this post was mind blowing , please add more mistress posts and I will be back all the time lol!
December 17th, 2010 on 8:04 AM
Hey Blogger, Next month I’ll be starting my expat blog about making money while traveling. I will be working as a “professional” blogger and freelance writer, and probably teach a little English as well. My blog will be an adventure and I hope anyone interested in long term travel will subscribe. It will be fun (A Broad Abroad) so please subscribe to me.
See me on Facebook http://www.facebook.com/people/Pearl-Perras/100001813539215
October 19th, 2011 on 6:36 AM
I used to be very happy to find this web-site.I wished to thanks for your time for this wonderful read!! I undoubtedly having fun with every little bit of it and I have you bookmarked to take a look at new stuff you blog post.
October 29th, 2011 on 1:29 PM
Please let me know if you’re looking for a author for your weblog. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write some content for your blog in exchange for a link back to mine. Please blast me an email if interested. Cheers!
November 16th, 2011 on 11:45 AM
My wife and i were quite lucky when Albert could conclude his preliminary research via the ideas he made from your web site. It’s not at all simplistic just to be handing out points that many some people might have been trying to sell. We discover we have you to be grateful to because of that. These illustrations you made, the easy website navigation, the relationships you can assist to promote – it is most fantastic, and it’s really helping our son in addition to the family do think that theme is satisfying, which is certainly highly indispensable. Many thanks for everything!
November 25th, 2011 on 2:01 AM
Good idea of article. I’m from Czech Republik I read many publication about it. I wondered idea of article is quite best and impresive to think about this article and future. Kind regards from Slovakia.
December 3rd, 2011 on 10:07 AM
You might be so great, gentleman! I are unable to trust I missed this blog site for so prolonged. It can be just superb things all spherical. Your style and design, gentleman…also impressive! I are unable to wait around to study what you’ve got bought future. I really like every little thing that you might be declaring and want alot more, a great deal more, Much more! Retain this up, guy! It is really just as well excellent.
January 7th, 2012 on 11:12 AM
Hey, i’ve been browsing this blog page for any despite the fact that and also have a issue, perhaps you possibly can benefit… it is really how do i include your feed to my rss reader as i would like to adhere to you. Many thanks.