Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Database replication is a great way to ensure resilience of critical data am get back to business as soon as possible.
- The following are steps in setting up mysql replication. The procedure shows setting a single master and slave database.
- You can however scale the number of slaves just by giving each slave a unique ID.
- There are tasks that are common across all replication setup:
- 1. On the master, you must enable binary logging and configure a unique server ID. This might require a server restart.
- 2. On each slave that you want to connect to the master, you must configure a unique ID. This might require a server restart.
- 3. Create a separate user for your slaves to use during authentication with the master when reading the binary log for replication.(This is optional)
- 4. Note down the current position in the binary log from the Master database. You need this information when configuring the
- slave so that the slave knows where within the binary log to start executing events.
- 5. Configure the slave with settings for connecting to the master, such as the host name, login credentials, and binary log file name and position.
- ####### CONFIGURING The MASTER #######
- (Using binary log file position based replication)
- Step 1. To Enable binary logging and establish a unique server ID, shut down the MySQL server (service mysqld stop);
- Then add the below two lines in the my.cnf file or its windows equivalent my.ini under [mysqld] entry.
- In linux, this is normally located at /etc/my.cnf
- log-bin=mysql-bin
- server-id=1
- log-bin: is the prefix name of the binary logs. it is created in the data directory of mysql, usually located at /var/lib/mysql
- if this option is left blank, the master will use the host name as the log-bin value.
- You can also give an absolute path to where this logs will be stored.
- server-id: is the unique id given to each entity in a replication environment. It must be a positive interger between 1 and (232)−1
- If these options already exist, but are commented out, uncomment the options and alter them according to your needs
- After making the changes, restart the server.
- Step 2: Create a user in the master that will be used by the slave to authenticate for replication purpose. Remember, it's the slave that drives the process.
- To create users, log in to your mysql server with a user that has create user and grant privileges, otherwise the followinf will not work.
- CREATE USER 'User_Name_Goes_Here'@'Host_goes_here' IDENTIFIED BY 'the_password';
- GRANT REPLICATION SLAVE ON *.* TO 'User_Name_Goes_Here'@'Host_goes_here';
- example. Say we want to create a user with the name= "replication", password = "replPass" and the host from where the slave sits and will connect from is 192.168.0.6 we would do this.
- CREATE USER 'replication'@'192.168.0.6' IDENTIFIED BY 'replPass';
- GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.6';
- Step 3: Record a bin log position from where our slave will start reading replication events.
- To get a master bin log cordinate, run the following query in the master:
- mysql> show master status;
- +------------------+-----------+--------------+------------------+-------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
- +------------------+-----------+--------------+------------------+-------------------+
- | mysql-bin.000005 | 171690390 | | | |
- +------------------+-----------+--------------+------------------+-------------------+
- 1 row in set (0.00 sec)
- You should get output that is similar to the above, however if your master has not data and binary logging was previously not enable, it will return
- And that's it for the Master. Now to slave configuration.
- ####### CONFIGURING The Slave #######
- Configuring the slave is pretty easy:
- Step 1: Stop the slave mysql and add 'server-id' to the my.cnf file of the slave. It should be different from the ID set in the master. After this, restart the slave server. service mysqld restart.
- step 2:
- options:
- log-bin=mysql-bin
- server-id=1
- max_binlog_size=1073741824 (size if bin-log before rolling (master))
- binlog_format =STATEMENT (server/slave)
- expire_logs_days = 7
- binlog-ignore-db = "mysql" (slave)
- CHANGE MASTER TO
- MASTER_HOST='172.17.0.16',
- MASTER_USER='DRCRepl',
- MASTER_PASSWORD='inmobia',
- MASTER_LOG_FILE='mysql-bin.000005',
- MASTER_LOG_POS=119532836;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement