Mysql Master - Master Replication and mysql-bin.log Rotation issues - mysql

I have successfully synced my primary and secondary databases using Mysql Master - Master Replication( guide: https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication ). Well I am stuck with a weird issue. Every time the mysql service is restarted the value of mysql-bin.xxxxxx file gets incremented(eg: mysql-bin.000005 to mysql-bin.000006) and it stops the master - master replication process. How can I prevent the mysql-bin file value rotation or is there any way to deal with this increment issue so that even if the rotation happens the replication wont get affected?
Thanks :)
Update
As usual I had to find the answer for my own question, here is the solution for those who are facing the same situation. Just added the line log_slave_updates=1 to my.cnf file in both the servers.
Master - Master Repication:
Primary my.cnf:
#bind-address=127.0.0.1
server-id=1
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=db_name_1
binlog_do_db=db_name_2
binlog_do_db=db_name_3
max_binlog_size=100M
log_slave_updates=1
auto_increment_increment=2
auto_increment_offset=1
Secondary my.cnf:
#bind-address=127.0.0.1
server-id=2
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=db_name_1
binlog_do_db=db_name_2
binlog_do_db=db_name_3
max_binlog_size=100M
log_slave_updates=1
auto-increment-increment=2
auto-increment-offset=2

Related

MySQL Master-Slave Replication When Master is Down

I'm running MySQL as the database on Ubuntu instances. I'm using MySQL Master-Slave replication where master's changes will be written to slave and slave's changes will not be reflected on the master. That's fine. I'm using a HAProxy load balancer to front the MySQL instances where all the requests will be sent to master MySQL instance. If the master MySQL instance is down slave MySQL instance will act as master and HAProxy will send all the requests to salve. Active-Passive scenario.
HAProxy - 192.168.A.ABC
MySQL Master - 192.168.A.ABD
MySQL Slave - 192.168.A.ABE
Let's assume that the MySQL master(192.168.A.ABD) is down. Now all the requests will be sent to MySQL slave(192.168.A.ABE) by HAProxy where now he acts as the master MySQL server for the time being.
My problems are
What happens when original master MySQL instance(192.168.A.ABD) is up?
Will changes written to new MySQL master (192.168.A.ABE) be replicated to original master(192.168.A.ABD) again?
How should I address this scenario?
First of all I should say that I have never used HA Proxy so con't comment on that directly.
However, in your current setup the Master (ABD) will be out of sync, and wont catch up. You will have to rebuild that using mysqlDump or similar tool.
What you would need is a Master < > Master setup (as opposed to Master > Slave), which enables you to write to either database and have it reflected in the other. This isn't quite as straight forward as it sounds though.
Assuming you already have your master > slave setup, and they are in sync
On the Master (ABD) you want to add:
auto_increment_increment=2
auto_increment_offset=1
log-slave-updates
On the Slave (ABE) add:
auto_increment_increment=2
auto_increment_offset=2
log-slave-updates
to your my.cnf files. Restart the Database. This will help to prevent Duplicate Key Errors. (n.b. that log-slave-updates isn't strictly required but makes it easier to add another slave in future)
Next you want to tell the Master (ABD) to replicate from the Slave (ABE).
Depending on what version of MySQL and if you are using GTID etc. the exact process differs slightly. But basically you are going to issue a CHANGE MASTER statement on the Master so it replicates from the slave.
And away you go. You probably want to avoid writing to both at the same time as that opens up a whole other kettle of fish. But if the Master goes down, you can switch your writes to the slave, and when the master comes back up, it will simply start replicating the missing data.
I am considering you scenario
Master - 192.168.A.ABD
Slave - 192.168.A.ABE
You cannot directly add the master in system. To Add master in system you need to perform below steps:
1) When master is up you can add this as a slave. So now this happens
Master - 192.168.A.ABE
Slave - 192.168.A.ABD
2) Then Now U can put master Down. Means You can put 192.168.A.ABD Down
3) Then Again Add this as slave. So After this You will get below scenarion
Master - 192.168.A.ABD
Slave - 192.168.A.ABE
You can refer this link
https://dev.mysql.com/doc/refman/5.5/en/replication-solutions-switch.html

Master to Master Replication: Clogged until restart

I have got master - to master replication installed.
It all works fine, until you break the link between two servers.
Once it's broken the data won't go from one to another if it exceeds some kind of limit.
Max_packet size is set to 500mb.
However, if you restart the server (mysqld) where the data is clogged (on secondary) it will push it throught.
Nothing in the log file related to this.. Any ideas?
Configuration for primary:
[mysqld]
innodb_file_per_table=1
server-id=6935500
log_bin=mysql-bin
binlog_format=ROW
log_error=/var/log/mysql-bin.err
#binlog_do_db=devjump_dev
binlog_do_db=crm_live
max_allowed_packet=500M
Configuration for secondary
[mysqld]
bind-address=0.0.0.0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=574271
log_bin=mysql-bin.log
binlog_format=ROW
binlog_do_db=crm_live
max_allowed_packet=500M
log_error=/var/log/mysql-bin.err
relay-log=mysqld-relay-bin
So apparently, after we break a link between these two some big packets are not being pushed into the binlog... From Primary to Secondary.
Thanks Guys,
Roman
After spending lots of hours reading and searching I have discovered that there was an issue with slave-net-timeout
It was defaulted to 3600 so it took 1 hour for the Secondary to find out there was a lag in the connection.
Resetting this to 60 seconds helped big time.
Hopefully someone might find this post useful and it will save their time.

Mysql master-master replication

I am trying to replicate my two instance of mysql databases located in different location.
Till now I am successful in replicating the databases. But suppose when one server is temporarily down, it stops sending its data to slave whereas another keeps on sending its data. This creates two different sets of database instances.
Is it possible to replicate the data from where it has been stopped.
This is my setup for replication:
Server 1:
server-id = 1
replicate-same-server-id=0
auto-increment-increment=2
auto-increment-offset=1
mysql> CHANGE MASTER TO MASTER_HOST='192.168.x.x', MASTER_USER='abcd', MASTER_PASSWORD='password', MASTER_LOG_FILE="mysql-bin.000003", MASTER_LOG_POS=98;
Server 2:
server-id = 2
replicate-same-server-id=0
auto-increment-increment=2
auto-increment-offset=2
mysql> CHANGE MASTER TO MASTER_HOST='192.168.x.x', MASTER_USER='abcde', MASTER_PASSWORD='password', MASTER_LOG_FILE="mysql-bin.000004", MASTER_LOG_POS=198;
Is there any way to continue the replication from where it has been stopped.
try 'stop slave; reset slave; start slave;'
I also encounter the issue. After I change to ROW mode, the issue is gone.
[mysqld]
server-id=1
log_bin=mysql-bin
binlog_format=ROW

On restart mysql flush mysql-relay-bin log files

I have mysql replication master-slave of slave i make backups.
I use mysql-relay-bin to restore mysql database on crash. The problem is that in every restart mysql-relay-bin is deleted and create a new.
How to stop the creation of new mysql-relay-bin file.
Usually a new log file is created whenever slave I/O thread starts, if your old relay logs get deleted, this means usually that the slave is in sync with master (all events are applied to the slave db). This means your setup works as intended.
If you need persistant log files on the slave, you should activate binary logging on the slave host (as you did on master for replication setup). Also you want the updates which are coming from replication itself, this is archieved using the log-slave-updates parameter. Here is an example of the mysqld conf on the slave:
expire_logs_days = 5
log-slave-updates = 1
log_bin = /var/lib/mysql/mysql-bin.log
For further information on the parameters refer to MySQL docs on replication options
Keep also in mind that this will cost you additional disk space and also requires a different backup strategy in order to perform point in time recovery of your db.

To stop master-slave replication with MySQL, do I need to issue any commands to master?

I have two mySQL databases set up as master-slave. Do I need to issue a command to the master to stop this replication?
From previous posts I understand that I have to issue the following commands to slave:
stop slave
reset slave
And add skip-slave-start to my.cnf
This question :
https://stackoverflow.com/questions/91814/how-do-i-completely-disable-mysql-replication
Addresses master-master. I'd like a similar answer for master-slave config please. Thanks in advance!
Till bin-log is enabled on master and server-id is set, it can be a master to any slave as I know. You can set server-id of master to 0 for disabling replication from master side.
Check article on mysql dev
If you only want to stop replication from the master to the slave, you don't have to do anything on the master. The master can chug along happily.
Though you should note that the master will still have binary log going, but you'll probably want that. : )