How To Set Up MySQL Database Replication On Fedora 10
How To Set Up MySQL Database Replication On Fedora 10Version 1.0 This tutorial describes how to set up database replication in MySQL. MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. This is not a backup policy because an accidentally issued DELETE command will also be carried out on the slave; but replication can help protect against hardware failures though. I will use Fedora 10 for the master and slave in this tutorial. I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 Preliminary NoteI'm using two Fedora 10 servers in this tutorial:
In this tutorial I will show how to replicate the database exampledb from server1.example.com (master) to server2.example.com (slave). I'm assuming that MySQL is already installed (e.g. as shown in chapter 10 on http://www.howtoforge.com/perfect-server-fedora-10-p4) and working on both servers. The database exampledb with tables and data is already existing on the master, but not on the slave.
2 Configure The Masterserver1: First we create a log directory for the MySQL bin-logs: mkdir /var/log/mysql Then we edit /etc/my.cnf; we have to tell MySQL for which database it should write logs (these logs are used by the slave to see what has changed on the master), which log file it should use, and we have to specify that this MySQL server is the master. We want to replicate the database exampledb, so we put the following lines into /etc/my.cnf (in the [mysqld] section!): vi /etc/my.cnf
Then we restart MySQL: /etc/init.d/mysqld restart Then we log into the MySQL database as root and create a user with replication privileges: mysql -u root -p Enter password: Now we are on the MySQL shell. STOP SLAVE; Next (still on the MySQL shell) do this: USE exampledb; The last command should show something like this (please write it down, we'll need it later on): mysql> SHOW MASTER STATUS; Now don't leave the MySQL shell, because if you leave it, the database lock will be removed, and this is not what we want right now because we must create a database dump now. While the MySQL shell is still open, we open a second command line window where we create the SQL dump snapshot.sql and transfer it to server2 (using scp): cd /tmp Afterwards, you can close the second command line window. On the first command line window, we can now unlock the database and leave the MySQL shell: UNLOCK TABLES;
3 Configure The Slaveserver2: Now we have to tell MySQL on the slave that it is the slave, that the master is 192.168.0.100, and that the master database to watch is exampledb. Therefore we add the following lines to the [mysqld] section in /etc/my.cnf: vi /etc/my.cnf
Then we restart MySQL: /etc/init.d/mysqld restart Now we create the empty database exampledb on the slave (make sure you run STOP SLAVE; to stop all slave processes if there are any!): mysql -u root -p Enter password: STOP SLAVE; We can now import the SQL dump snapshot.sql as follows: cd /tmp Then we connect to MySQL again... mysql -u root -p Enter password: ... and run the following command to make server2 a slave of server1 (it is important that you replace the values in the following command with the values you got from the SHOW MASTER STATUS; command that we ran on server1!): CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98; Finally start the slave: START SLAVE; Then check the slave status: SHOW SLAVE STATUS\G It is important that both Slave_IO_Running and Slave_SQL_Running have the value Yes in the output (otherwise something went wrong, and you should check your setup again and take a look at /var/log/mysqld.log to find out about any errors): mysql> SHOW SLAVE STATUS\G Afterwards, you can leave the MySQL shell on server2: quit; That's it! Now whenever exampledb is updated on the master, all changes will be replicated to exampledb on the slave. Test it!
4 Links
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com
Red Hat Virtual Experience - a free virtual event. Dec. 9th







Recent comments
6 hours 33 min ago
12 hours 21 min ago
14 hours 13 min ago
15 hours 58 min ago
19 hours 48 min ago
1 day 1 hour ago
1 day 1 hour ago
1 day 6 hours ago
1 day 11 hours ago
1 day 16 hours ago