MySQL replication, master only replicate a portion data to slave - mysql

I have a master/slave mysql deployment.
And success to do replication.
But after several weeks. Only a portion of data replicate to slave.
It's not the network. Because it replicate indeed but a portion lose.
I've check show master status\G; and show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
and
Master_Log_File: mysql-bin.000016
Read_Master_Log_Pos: 515965048
is OK also. master_log_pos is up to date with the master.
Notice. The table of master is MyISAM and the corresponding table of slave is InnoDB.
I don't think it's an issue.

There is a number of variables on the slave that effects replication.
On the slave it's the replicate-do-* and --replicate-ignore-*. You should read through that part of the manual

Related

Replicate NDBCluster to InnoDB

We operate a NDBCluster Version 8 and want to replicate a database in this cluster into a "standalone" InnoDB Database System. I followed this guide to implement the replication:
http://johanandersson.blogspot.com/2012/09/mysql-cluster-to-innodb-replication.html
but it seems, I have done something wrong and I don't know, how to debug it. I know the guide is very old, but I also read the chapter about the NDB Replication on MySQL https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-replication.html
Current behavior
The replication I set up by now replicates every statement like "Create Database" or "Create Table", even "INSERT" and "UPDATE" statements, as long as the NDBCLUSTER as Engine is not involved. I.e.: I can create a new Database in the cluster and it will be perfectly replicated to the slave. I can insert new datarows to a InnoDB table that I created on the cluster (I know, it is not actually saved in the cluster) and those data rows will be replicated to the slave. Inserting new data rows to a NDBCLUSTER table will result in no replication at all. If I execute the statement "SHOW MASTER STATUS" on the SQL Node in the Cluster before the insert to a NDBCLUSTER table and afterwords, I can see, that the Binlog Position has not changed at all.
Wanted behavior
I want the Replication to replicate data from tables with the NDBCLUSTER Engine to my Slave, that runs on InnoDB. I know there are limitations and we have to be carefull how to structure tables, that everything is compatible, etc.
Current Setup
We operate a MySQL NDB Cluster with 2 Management Nodes, 2 SQL Nodes and 4 Data Nodes and we want to replicate to one InnoDB Server
All Systems have Version 8 installed, run on Ubuntu 18.04 and all Systems have the Cluster Version of the MySQL Server installed. On of the SQL Nodes is chosen to do the replication. The config (/etc/my.cnf) of the Slave in the mysqld section is:
server-id=101
log-slave-updates=0
log-bin=binlog
binlog-format=MIXED
slave-exec-mode=IDEMPOTENT
expire-logs-days=5
The config of the Master (/etc/my.cnf) in the mysqld configuration (besides some cluster specific configuration) is:
binlog-format=ROW
log-bin=binlog
server_id=120
They are both at the same Position regarding the Binlog file.
mysql> SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000002 | 10547 | | | |
+---------------+----------+--------------+------------------+-------------------+
mysql> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.175.110
Master_User: replicationUser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000002
Read_Master_Log_Pos: 10547
Relay_Log_File: innodb-1-relay-bin.000005
Relay_Log_Pos: 365
Relay_Master_Log_File: binlog.000002
Slave_IO_Running: Yes
Slave_SQL_Running: No
[...]
Any Help in how to solve this Situation is appreciated!
Since MySQL Version 8.0.16 in addition to "log-bin" also a second variable has to be set in the my.cnf of the master & slave:
ndb-log-bin=ON
See https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-options-variables.html#sysvar_ndb_log_bin for more information.

Syncing remote MySQL database with localhost from the first inserted records with MySQL Replication

I have a database myDB in the remote server (master) which has a table myTBL with some records. I want to sync the remote database with my localhost (slave) using MySQL Replication. So I have created the replication user in master and also a database with the name of myDB and the myTBL table in the localhost.
I want to use GTIDs method to syncing my databases because there is a description in MySQL website as follows:
MySQL 8.0 supports different methods of replication. The traditional
method is based on replicating events from the master's binary log,
and requires the log files and positions in them to be synchronized
between master and slave. The newer method based on global transaction
identifiers (GTIDs) is transactional and therefore does not require
working with log files or positions within these files, which greatly
simplifies many common replication tasks.
My master MySQL mysqld.cnf has:
server_id=1
enforce_gtid_consistency = on
gtid_mode = on
log_bin
log_slave_updates
and the status is:
File: ***-bin.000001
Position: 314969
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 9a670a45-be0a-11e9-be56-52540055d8e4:1-368
and my salve mysqld.cnf has:
server-id = 2
read_only = 1
gtid_mode=ON
enforce-gtid-consistency=ON
skip-slave-start=ON
and I use the following commands to start syncing in slave:
CHANGE MASTER TO MASTER_HOST='***', MASTER_USER='***', MASTER_PASSWORD='***', MASTER_AUTO_POSITION=1;
start slave;
And every thing is OK with this status in slave:
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
So, every new record that inserted to master database is synced with my slave (localhost) database. But the records which are inserted before syncing do not placed in localhost. How can I sync them? Or in the other words, How do I start syncing from the first records? (I saw in some websites which proposed using mysqldump to dump the first data, is there a better way?)

MariaDb 10.1 Master-Slave lost or not syncro

I've a system with Master-Slave based on MariaDB 10.1
After down master server, I stop slave, and put sites, to use slave how dbhost.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Last_Errno: 0
Last_Error:
What is my surprise that when going to use the slave server, stop the master-slave model, while the master computer restarted, the difference between the data was 1 hour.
This is a mistake? This is common? The Master-Slave model is a chimera? There's something I've done wrong?

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 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 !