MariaDb 10.1 Master-Slave lost or not syncro - mysql

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?

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?)

Mysql slave last error and sql thread

I use the show slave status\G and the result is as follows:
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1008
Last_Error: Error 'Can't drop database 'hehe'; database doesn't exist' on query. Default database: 'hehe'. Query: 'drop database hehe'
And I guess the reason Slave_SQL_Running being NO is that the Last_Error, because I handly create a table on the master db before I build the master-slave cluster, and then I drop the table on the master.
Is there a way to alert people when this situation is occured? Like sending mail or sms?
Best way is
Manually: Execute SHOW GLOBAL STATUS like 'slave_running' and SHOW
SLAVE STATUS periodically and store it in a file. Check the contents
of the file periodically to see if any of your replicas have stopped
replicating. On Linux, you can have a cron job setup which executes
these queries periodically and even configure to send email alert if
slave_running value is ‘NO’.
For more

MySQL replication, master only replicate a portion data to slave

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

Replicate tables from different database of same mysql server

I have one server with 2 databases, and i want to replicate several tables from one database to another. Purpose is that we uses same user's table that used in projects.
As in anothers tables used InnoDB with foreign keys to users table i've chosen a replication way.
For that I made the changes for my.cnf
master-user=root
server-id = 2
replicate-rewrite-db = dou->jobs
replicate-do-table = jobs.auth\_user
replicate-wild-do-table = jobs.geo\_%
replicate-do-table = jobs.user\_profile
replicate-same-server-id = 1
report-host = master-is-slave
binlog-do-db = dou
log-bin
after syncing tables from binlog-do-db and starting slave error.log next lines appears:
111112 15:10:22 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='localhost', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='localhost', master_port='3306', master_log_file='mysql-bin.000074', master_log_pos='106'.
111112 15:10:36 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000074' at position 106, relay log '/var/log/mysql/dell-relay-bin.000001' position: 4
111112 15:10:36 [Note] Slave I/O thread: connected to master 'root#localhost:3306',replication started in log 'mysql-bin.000074' at position 106
Seems that on this step everything is ok, and show slave status shows no errors.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000074
Read_Master_Log_Pos: 814
Relay_Log_File: dell-relay-bin.000002
Relay_Log_Pos: 959
Relay_Master_Log_File: mysql-bin.000074
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: jobs.user\_profile,jobs.auth\_user
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: jobs.geo\_%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 814
Relay_Log_Space: 1113
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
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
ERROR:
No query specified
The thing is that master changes does not affect slave but slave status changes.
Thanks for any help in solve that problem.
I won't tell you that replicating table to the same DB is bad idea, cause of several times increased IO.
Slave is not updated, because server-id is the same for both master and slave. Usually slave ignores updates with the same server-id as it's own.
Add replicate-same-server-id to my.cnf. replicate-same-server-id documentation
Out of interest would a view do what you want?
I really don't think running replication on the same instance of mysql into to the same instance is a good idea.
The other option you might want to investigate if server hardware is a problem, would to run multiple instances of mysql running off different ports on the same machine, which might help you achieve what you are looking for. This is something i am using in a test environment for simulated master DB failure and slave DB promotion.
There is many situations on where you can achive more optimisations for example. DB1 replicates to DB2 (same server). From where DB2 only has data stored for as long as 1 week. all data that is older than 1 weeks gets deleted (On db2). in such a setup for example a high traffic db server where u need it to be as clean as possible a dual db setup on the same server uses "less" resources from the server if what your server do most of the time is read data from the database. I have such a setup buth i use 4 diferent servers. server 1) 3 days. server 2) 30 days. server 3) 2 months, and server 4 all data from start. (Server 4 mostly used for gething very old registers not so much used. Sorry for my english buth i think i made a point on where you CAN and should use db replication on the same server to reduce memmory usage and cpu usage.