How to reduce MySQL replication delay - mysql

I have two MySQL Enterprise servers for master host and slave host. Replication has been setup successfully and works grate.
One day I have to kill query from master and then stop the slave. Then I had skip counter + 1 relay log and start slave again.
Then replication is not done real time and there is a time gap between master and slave.
Seconds_Behind_Master = 12222
How can I reduce this delay.

Related

Mysql replication recovery after Slave Reset

I had MySQL master slave replication configured. I accidently ran Reset Slave on slave instance. I do not have a note of the last bin log position of the master that the slave had completed. Show slave status command returns a blank row as I have reset the slave.
Is there any way in which I can recover the last bin log position that the Slave had finished syncing? Or is there any other way in which I can fix the replication without setting it up fresh?

Replication not updating all tables

Master db MySQL db Server 2012
Slave db MySQL Win7 XAMPP
DB size 500MB
Table count 42
I have setup the replication successfully however it stopped last week and my slave was showing the error Slave_SQL_Running No. I realised that it was looking at an incorrect log file (00004 whereas it should have been 00006).
I have since sorted this by;
At the MASTER;
SHOW MASTER STATUS;
Copied the values of MASTER_LOG_FILE and MASTER_LOG_POS.
At the SLAVE;
STOP SLAVE;
RESET SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98; (<- example values)
START SLAVE;
SHOW SLAVE STATUS \G;
On my master I tested the replication by editing the table members - I edited one of the row values (from 85 to 86 - this successfully replicated in my slave). However I notice that on my master members table there are 70652 members but on my slave there are only 70056.
I added two new members to my master members table and the total increases by 2 on both tables. However there still seems to be that 600 missing?
What could be the problem? Replication seems to be working but totals aren't. New members are added to the members table each day, but the aren't being added to my slave members table.
The results of my slave status table (from phpmyadmin) are;
Slave_IO_State Waiting for master to send event
Master_Host xxx.xxx.xxx.xxx
Master_User repl
Master_Port 3306
Connect_Retry 60
Master_Log_File mysql-bin.000006
Read_Master_Log_Pos 787956776
Relay_Log_File mysql-relay-bin.000004
Relay_Log_Pos 624412
Relay_Master_Log_File mysql-bin.000006
Slave_IO_Running Yes
Slave_SQL_Running Yes
Replicate_Do_DB
Replicate_Ignore_DB
Replicate_Do_Table
Replicate_Ignore_Table
Replicate_Wild_Do_Table
Replicate_Wild_Ignore_Table
Last_Errno 0
Last_Error
Skip_Counter 0
Exec_Master_Log_Pos 787956776
Relay_Log_Space 788197
Until_Condition None
Until_Log_File
Until_Log_Pos 0
Master_SSL_Allowed No
Master_SSL_CA_File
Master_SSL_CA_Path
Master_SSL_Cert
Master_SSL_Cipher
Master_SSL_Key
Seconds_Behind_Master 0
Is there something else that I could check or test?
Yes, when you stopped the replication was some rows changed or inserted. After this you have RESET the SLAVE and set the MASTER_LOG_POS. So the replication NEVER can gets the old changes.
You have 2 Options:
First:
Stop Replication
Dump the Master DB (with master position)
Restore it in the Slave
set set Position or check them
start slave
second
Stop slave
sync the masterDB to Slave DB with percona Toolkit - pt-table-sync
Start slave

Mysql Replication SLAVE go down

I have a problem with mysql replication.
I configure two virtual host.
Server 1 Apache + mysql Ver 15.1 Distrib 5.5.41-MariaDB
Master and SLAVE OF Server2
Server 2 mysql Ver 14.14 Distrib 5.5.42
Master and SLAVE OF Server1
Topologi MASTER + MASTER
When I restart slaves all work good, short latency and fast update. But when I wait a few minutes the replication not work more. If I update some row or make a insert or delete the slave not update the changes.
The logs not write any error, but the master_position_log is diferent between master and slave.
And if I restart the slaves all works again, the bdd is updated and the replication works well.
I don't know what happen, seems the threads sleep or death.
Thanks for some idea for fix the problem
In two cases the processes seems ok.
SERVER1
Kill 168 system user None Connect 1146 Waiting for master to send event ---
Kill 169 system user None Connect 945 Slave has read all relay log; waiting for the slave I/O thread to update it ---
Kill 170 master XXXXXXX:59273 None Binlog Dump 1145 Master has sent all binlog to slave; waiting for binlog to be updated ---
SERVER2
Kill 73 root XXXXXX:55089 None Binlog Dump 1137 Master has sent all binlog to slave; waiting for binlog to be updated ---
Kill 76 system user None Connect 1137 Waiting for master to send event ---
Kill 77 system user None Connect 985 Slave has read all relay log; waiting for the slave I/O thread to update it ---
The problem is latency.
My solution, create a CRON every minut for stop and start slave.
Now all works.
Cristian
SHOW SLAVE STATUS;
on each server. That is likely to tell you what is wrong.
You do understand the potential problems with AUTO_INCREMENT and UNIQUE keys when you are writing to both heads of a dual-Master topology?

MySQL master-slave after crash

Here's the scenario:
I have one MySQL Master and 1 slave.
master-slave replication is set and works perfectly.
The slave machine crashes.
The master machine is still up and running.
Nothing changes in the master DB.
I start the slave machine again.
I start the slave MySQL DB.
Do I need to invoke "start slave" again on the slave DB ?
10x.
I believe the slave will start automatically unless you have skip-slave-start in your my.cnf.
Run 'SHOW SLAVE STATUS' and see what it says.
In master, check the status of the master and see it shows slave is running or not.
Goto slave machine and restart(stop & start) the slave machine.
Repeat the step 1 to check again

MySQL Master-Slave-Slave Configuration

Quick questions about MySQL Master-Slave-Slave set-ups:
I currently have a Master-Slave set up right now and I would like to add another slave. Would it be possible to clone the server running the slave, and then spin up a new server with the image from the slave, and have it pick up right where it left off? So whatever the binlog was at the time of the copy it would just run until it catches up with the master?
Ideally - I'm trying to start another slave the connects to the master without shutting down the Master for a backup. Any advice or guidance would be great. Thanks!
Yes, you can shutdown slave instance, and copy all it's data to another slave (including logs).
Don't forget to edit my.cnf on second slave (you should change server-id)
Then start both slave servers
Yes this is possible. The best way would probably be to temporarily pause the replication on the slave, determine the master binary log position information, then make your dump from the replica while replication is still paused (and no other data is changing on the replica). After the dump is complete you can restart the replica.
On the new server, just install the dump, set the binlog coordinates and start up the replication. A word of caution though. Make sure your settings for purging the binary logs on the master will allow for retention of the binary logs for long enough for you to do this set up process and get the new slave caught up before the bin logs are purged.
Here's a good tutorial on how to setup multiple replication slaves for a master server:
http://arcib.dowling.edu/cgi-bin/info2html?%28mysql%29replication-howto
It doesn't explain your scenario, but gives important hints: you must assign a unique server-id to your second slave.
Regarding your problem: If your masters binary log is kept long enough, you should not get into trouble. Just shutdown your slave for a moment, clone it and write down: MASTER_LOG_FILE and MASTER_LOG_POS of the slave; then restart the original slave and setup the second slave correctly: that means with that given MASTER_LOG_POS and *_FILE set and a unique server-id in my.cnf;
Then start up your second slave. Use "START SLAVE" to start the replication and then have a look at "SHOW SLAVE STATUS;"
Regards,
Stefan
PS: Cannot promise this to work, but I'm quit sure it should do.
You can use existing mysql slave to make a new one just do the following steps,
Stop replication on slave.
execute show slave status; and note these values Master_Log_File: master-bin.000002 &
Read_Master_Log_Pos: 1307
Take mysqldump and restore it on new mysql slave server, you can copy my.cnf file from existing mysql slave server and just change server-id.
execute change master to command on new slave server providing details of mysql master server and log file name and log position which we obtained from existing mysql slave.
execute start slave; on existing mysql slave.
to verify slave status run show slave status.
that's it you have a new mysql slave server!!
Good luck !