MySQL Master-Master replication error 1062 - mysql

The question is about MySQL-Master-Master replication. I have read a lot on the Internet, but there is a problem.
Source data:
A. MySQL 5.7.
Part of my. cnf about replication:
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay-log = /var/log/mysql/mysql-relay-bin
relay-log-index = /var/log/mysql/mysql-relay-bin.index
binlog_do_db = example
expire-logs-days = 7
auto_increment_increment = 2
auto_increment_offset = 1
log-slave-updates = 1
B. MySQL 5.7.
Part of my.cnf about replication:
server-id = 2
log_bin = /var/log/mysql/mysql-bin. log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay-log = /var/log/mysql/mysql-relay-bin
relay-log-index = /var/log/mysql/mysql-relay-bin.index
binlog_do_db = example
expire-logs-days = 7
auto_increment_increment = 2
auto_increment_offset = 2
log-slave-updates = 1
Server A is the active (primary) database server. Server B connects when server A is disabled / unavailable. In the beginning, the Master-Master replication was assembled (replication worked in both directions) and successfully worked for 2 days until I decided to test it. I started blocking access to server A to switch to server B and back. After several switches replication error 1062 appeared (Could not execute Write_rows event on table...).
And now question. What is incorrectly configured in my replication configuration? I understand that a lot depends on the product and the requests to it, but is there a universal Master-Master config?

Please consider below steps to test connection or failover:
let's assume, server A is active. So
enable read only first on server A.
then wait for couple of seconds and check show slave status twice
if positions are not changing. then move traffic on server B.
Follow same steps to reverse traffic on server A.

Related

MySQL replication - Slave won't start mysql service

I'm testing MySQL replication on two virtual machines with VirtualBox running Debian 8.2.
Following tutorials, this is how I set the slave's /etc/mysql/my.cnf:
server-id = 2
master-host = 192.168.56.101
master-connect-retry = 60
master-user = slave
master-password = 123
replicate-do-db = base1
replicate-do-db = base2
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
However, doing so also won't let me start mysql. When I run /etc/init.d/mysql start, it fails. These are the two errors that appear on the logs:
error: Can't connect to local MySQL server through socket '/var/run/mysql/mysqld.sock' (2)
Failed to start LSB: Start and stop the mysql server database daemon
Commenting the master-zzz lines allow mysql to start without a hitch.
The virtual machines can see each other and ping without loss. I've tried changing the my.cnf's master-user and password, as well as creating different replication slave users on the master server, to no avail. What am I doing wrong?
Well, turns out the tutorials I was following were a bit outdated. These are the final configurations of my.cnf files:
#master
bind-address = 0.0.0.0
server-id = 1
log-bin= /var/log/mysql/mysql-bin.log
#slave
server-id = 2
Instead of setting the slave's my.cnf, I used the mysql console:
CHANGE MASTER TO master_host='master_ip', master_user='slave', master_password='slavepass';
As per this manual's instructions: https://downloads.mysql.com/docs/mysql-replication-excerpt-5.0-en.pdf

one server is not updating data in tungsten replicator correctly

i am using tungsten replicator
i have 3 servers
all masters
i used following mysql configuration to avoid primary key violation
server 1:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
binlog_format = row
innodb-file-per-table=1
server-id=1
log-bin=mysql-bin
innodb-flush-method=O_DIRECT
max_allowed_packet=52M
innodb-thread-concurrency=0
default-storage-engine=innodb
auto-increment-offset = 1
auto-increment-increment = 10
innodb_flush_log_at_trx_commit=2
sync_binlog=1
server 2
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
binlog_format = row
innodb-file-per-table=1
server-id=2
log-bin=mysql-bin
innodb-flush-method=O_DIRECT
max_allowed_packet=52M
innodb-thread-concurrency=0
default-storage-engine=innodb
auto-increment-offset = 2
auto-increment-increment = 10
innodb_flush_log_at_trx_commit=2
sync_binlog=1
server 3
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
binlog_format = row
innodb-file-per-table=1
server-id=3
log-bin=mysql-bin
innodb-flush-method=O_DIRECT
max_allowed_packet=52M
innodb-thread-concurrency=0
default-storage-engine=innodb
auto-increment-offset = 3
auto-increment-increment = 10
innodb_flush_log_at_trx_commit=2
sync_binlog=1
few days ago server3 suddenly restarted but replicator service and mysqld service did not restart that's why server 3 gone offline with some error
we restarted the mysqld and replicator service and make the server online by skipping some transaction by force.
after that now all servers/nodes in tungsten replicator status are showing online but server 2 is not getting all updates from other servers (1 and 3). but all updates in server 2 is propagating to other servers (1 and 3). but almost 50% updates work with huge delay.
it seems server 3 is working perfectly that stopped but server 2 is not working perfectly. server 2 only can send all updates to other servers but can't get all updates from other servers (one way update is working right now but opposite are not working properly but almost 50% updates work with huge delay).
can anyone please tell me what is the reason behind this and how to fix?
status:
cookbook/trepctl services
Processing services command...
NAME VALUE
---- -----
appliedLastSeqno: 178188705
appliedLatency : 0.931
role : master
serviceName : alpha
serviceType : local
started : true
state : ONLINE
NAME VALUE
---- -----
appliedLastSeqno: 178062709
appliedLatency : 53.53
role : slave
serviceName : bravo
serviceType : remote
started : true
state : ONLINE
NAME VALUE
---- -----
appliedLastSeqno: 176098723
appliedLatency : 0.851
role : slave
serviceName : charlie
serviceType : remote
started : true
state : ONLINE
Finished services command...
anyone please help

Setting up MySQL master - master replication

I currently have one master server and want to add another master server for fail over.
On the primary server I've added the following to "my.ini"
server-id = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1
log_bin=mysql-bin
log_error=mysql-bin.err
binlog_do_db=1
binlog_do_db=2
binlog_do_db=3
binlog_do_db=4
Once adding:
master-host = [IP]
master-user = [usernameslaveuser]
master-password = [password]
master-connect-retry = 30
The mysql server no longer starts up...
So I decided to first get the secondary server to work properly.
Problem 2:
On the new server I've copied over my user files from the "data"/mysql dir of the primary.
I've also imported all databases with MySQL work bench.
Then I added this to "my.ini":
server-id=2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2
master-host = [IP]
master-user = [usernameslaveuser]
master-password = [password]
master-connect-retry = 30
log_bin=mysql-bin
log_error=mysql-bin.err
binlog_do_db=1
binlog_do_db=2
binlog_do_db=3
binlog_do_db=4
The server starts up fine, so I decided to add a table inside a replicating database on the master but the changes where not copied over to the secondary server...
I googled a bit and found that I have to run some commands in the mysql command line to make replication work.
But when I open this on the secondary server it doesn't start...
When opening it in the command prompt it says mysql.exe: unknown variable 'server-id=2"
Both servers are running Windows Server 2012 R2 and have MySQL 5.6.15 64bit installed.
Can someone guide me true the last part of setting this up?
Specifying as below in my.cnf(linux) or my.ini(windows) file is no longer supported in latest versions of MySQL
master-host = [IP]
master-user = [usernameslaveuser]
master-password = [password]
master-connect-retry = 30
You should execute this query instead:
CHANGE MASTER TO MASTER_HOST='host name/ip',MASTER_USER='user',MASTER_PASSWORD='pwd', MASTER_PORT=3306, MASTER_CONNECT_RETRY=30;
I've resolved problem 2: I wasn't putting it in the mysqld part but in the mysql part of the my.ini
Resolved problem 1: had to run it in the MySQL command line.

MySQL replication not updating slave

Trying to set up replication master - slave.
Master my.cnf
[mysqld]
bind-address = 0.0.0.0
port = 3306
server-id = 1
log-bin = /var/lib/mysql/mysql-bin
replicate-do-db = Test
Slave my.cnf
[mysqld]
log_output = "FILE"
general_log_file = /var/log/mysql/mysql.log
general_log = 1
log_bin = /var/log/mysql/mysql-bin.log
server-id = 2
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
replicate-do-db = Test
SHOW SLAVE STATUS shows
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
In relay log i see query executed on master.
And Read_Master_Log_Pos also updates.
But in general_log_file appear only
130530 14:50:25 523 Query BEGIN
523 Query COMMIT /* implicit, from Xid_log_event */
And changes on master not executed on slave. What i have missed?
This could be due to the following option:
replicate-do-db = Test
The replicate-do-db option can be very tricky and can sometimes behave in a manner that appears illogical.
It will only replicate statements where the default ((that is, the one selected by USE) database is set. So in your example that would mean that this is replicated:
use Test;
insert into myTable (column) values (value);
But this will not be replicated:
insert into Test.myTable (column) values (value);
Try using the replicate-wild-do-table option instead:
replicate-wild-do-table=Test.%
Hopefully you will get some joy.

MySQL replication Master-Slave

I am about to do a MySQL replication for my typo3 Database. There are two servers. You guessed it one is the Master and one is the Slave.
Master my.cnf:
[mysql]
server-id = 1
log-bin
expire_logs_days = 21
max_binlog_size = 500M
binlog-ignore-db=mysql
Slave my.cnf:
[mysql]
server-id = 2
binlog-ignore-db = mysql
replicate-ignore-db = mysql
auto-increment-offset = 1
expire_logs_days = 21
max_binlog_size = 500M
User on Master: repl#slaveip REPLICATION SLAVE, REPLICATION CLIENT
User on Slave: repl#masterip REPLICATION SLAVE, REPLICATION CLIENT
So far everything works, even if I change something on Master but if I delete the same thing on Master, Slave stops with this error message:
Last_SQL_Error: Error 'Duplicate entry '65021' for key 'PRIMARY'' on query. Default database: 'typo3'. Query: 'INSERT INTO sys_log (userid,type,action,error,details_nr,details,IP,tstamp,workspace) VALUES ('0','5','0','2','0','Core: Exception handler (WEB): Uncaught TYPO3 Exception: Reason: Segment "404" was not a keyword for a postVarSet as expected on page with id=0.<br />\n<br />\nAdditionally, http://www.21cdocs.de/404/ was not found while trying to retrieve the error document. | RuntimeException thrown in file /mnt/platte02/www/typo3/typo3_src-4.5.19/typo3/sysext/cms/tslib/class.tslib_fe.php in line 1542','masterip','1351240603','0')'
This is what show slave status\G shows me.
Any solutions how I force the Slave to override everything on it with Masters data?
- Timo
With slave-skip-errors = 1062 it skips the error but this isn't a good solution in my opinion
Update: obviously Typo3 is doing some mistakes on the sys_log table.