Thursday 26 June 2014

MySQL Replication CentOS All Databases

** THIS BLOG WORKS ONLY WITH MySQL VERSION 5.1 or EARLIER **
If you’re going to do it, do it right. Usually blogs have you do this for only 1 Database, that’s pretty much worthless, we’re going to do it right using the traditional Master/Slave Setup. This article assumes you have two Boxes with MySQL already installed, started, just not yet configured. Here’s what we have:
Standard Setup, Port 3306, same MySQL Version 5.1.69
MASTER = 192.168.1.241
SLAVE = 192.168.1.242
Let’s get Started!
Edit the MySQL configuration file on your master (you may want to make a backup)
 MySQL Replication CentOS All Databases
add these lines below the [mysqld] part somewhere
 MySQL Replication CentOS All Databases
now restart MySQL
 MySQL Replication CentOS All Databases
Now we have to create a slave user (service account) in order to process replications, so login to MySQL
 MySQL Replication CentOS All Databases
you prob. do not want to use the example credentials we have:
 MySQL Replication CentOS All Databases
now run the next few commands: MySQL Replication CentOS All Databases
now we need to write our Position Number down (it’s unique every time, this is our example, yours will be different)
exit to a shell, and dump the database info MySQL Replication CentOS All Databases
and Unlock all tables on Master
 MySQL Replication CentOS All Databases
now copy/sftp the .db to the SLAVE server.
from here, login and edit the MySQL config
 MySQL Replication CentOS All Databases
append the following to the config (please edit username/password and host if different)
 MySQL Replication CentOS All Databases
import your dump (do not yet restart MySQL until after you have imported the DUMP)
 MySQL Replication CentOS All Databases
modify the slave in MySQL
 MySQL Replication CentOS All Databases
 MySQL Replication CentOS All Databases
Perfect! It’s working! (if not check your username/password configuration for replication user in MySQL)
 MySQL Replication CentOS All Databases
Now to show off a bit:
create a database on the Master
 MySQL Replication CentOS All Databases
now let’s go to the slave:
 MySQL Replication CentOS All Databases

No comments:

Post a Comment