filter mysql replication (ignore-db) - mysql

mysql ignore-db works according to server my.cnf AFAIK,
i.e.
binlog-ignore-db = mysql
replicate-ignore-db = mysql
I am not sure, if this works from client side too, can anyone explain the mechanism, how can i be able to send from master but not accept in client side.
Why i want to do this? I have multiple slave "2 slave" must replicate MySQL table where as in other 2 should not be overwriten. Where as every other table will be replicated.
Reading this: http://dev.mysql.com/doc/refman/5.6/en/replication-rules-db-options.html didnt make me clear enough.

binlog-ignore-db is a master-side setting, it tells the Master not to log changes taking place on the listed DB.
replicate-ignore-db is a slave-side setting, it tells the Slave to ignore incoming log information related to the listed DB
The typical use case is when you want to replicate different databases from one single Master to different Slaves. The Master must log all changes occurring in all databases (minus those possibly excluded by binlog-ignore-db, i.e. database that will not be replicated anywhere).
Each Slave will receive the full binary log, but will only replicate changes related to the selected databases (i.e. databases not excluded by replicate-ignore-db -- this list would be different on each Slave).
(mysql database being a system database, it should be ignored from both ends, unless you really, really really know what you are doing).

Related

MySQL - How to grant access to only one of n slaves?

I have one master and two slaves.
Is it possible to restrict a particular read-only user to query only against the second slave (disallowing him from running any queries on the master and the first slave)?
I see that one can do the following to make un-replicated changes to the master, but what I think I need is to make changes to one slave and not the other.
SET sql_log_bin = {OFF|ON}
And the GRANT syntax allows one to limit what host users come from, but -- as far as I understand -- not which DB server(s) the person can use.
I didn't find much in a web search -- perhaps that's a hint that there's a better way to solve this problem. Basically I'm asking if this can be enforced by the database since the restriction I want applies to just this one user.
For context: a slave is basically just a server that copies every action that happened on the master. Depending on your configuration, the slaves will either just run the same queries that have been executed on the master, or apply a list of changes to individual rows to the slave.
To add a user just for a specific slave, you can do this directly on the slave. Anything you do here will only affect this slave. If your user currently exists on the master (and slaves), you would first have to drop him/remove his permissions, wait until this change has been replicated to all the slaves (which might also depend on your configuration), then add/modify this user directly on the slave.
You may need to temporarily disable a read_only or super_read_only setting (on the slave), which exists to prevent accidently executing something on the slave - but that is what you want to do.
Since your slave now deviates (slightly) from the master, if you would now run a query that alters that user on your master (e.g. drop it again), it might have a different effect on the master and the slave. This will depend on your configuration, but keep it in mind.

Connecting two databases

How can I connect two separate databases so that when some update is performed on a piece of data on one database , the change happens also on the data in the other one .?
this is really simple you must have 2 databases, 1 must be marked as a master, while other db must be slave. you 'll always insert data in master database, which will replicate this to slave database.
you must be careful because every change on master will be replicate to slave.
to understand the entire process here I am referring you to read this post

MySQL Local Database Replication

Is it possible to replicate a database to a second database in the same server?
I want to replicate a database that is used for an application, and create a copy that will be used for webservice testing puposes, like creating fake orders, fake data, etc... and it would be very nice to get updates from the main db, like product data updates...
I think i could use the binlog-do-db (or something similar) in mysql config and use the server as master and slave, but i played with that config before and had problems. In my current replications i replicate the entire mysql server, so it works.
Also, i dont want to replicate table1 to table1 and instead, table1 to table2. I dont know if thats allowed.
Is this the best approach or i'm trying to do something wrong/not possible? What would you recommend?
You might be tempted to try to set up a single mysqld instance as master and slave with replicate-same-server-id; this won't work, as the server-id must be unique between every other ID in use by any other replication master or slave.
See this Percona article on binlog-do-db et al. You could achieve this with running another mysqld instance on the same node, and configure on the slave replicate-rewrite-db to apply statements to a different database name. I do not see anything about rewriting table names in replication options, though.
Alternatively, depending on the size of the database you are looking to duplicate, you may mysqldump and import to another database.

How To Determine How Much Data Left In The Log

I have 2 servers set up using MySQL. It's using a standard replication setup, with one slave, no circular replication.
Is there a way to programmatically tell how far behind the slave is in reading the data from the binary log?
If I run the statement:
SHOW MASTER STATUS;
On the master, and run
SHOW SLAVE STATUS;
on the slave, I can compare the Position column from master status, and the Read_Master_Log_Pos column from slave status to determine how far behind the slave is.
However, this only works if the slave is reading from the same file the master is writing to. So if the slave is still reading a previous log file, because it is running behind, I can't figure out how to determine how much data is left until it catches up to the current position that the master is at. A solution using only SQL would be optimal, but I'm open to other solutions. Hopefully not one that requires reading the directory containing the log files.
I like to use the 'Seconds_behind_master' field from SHOW SLAVE STATUS in order to determine if the MASTER-SLAVE servers are caught up. As a secondary guard I also to a COUNT(*) query on a specific table (ie one that gets updated frequently) on both servers and then compare the record counts.

MySQL Replication: Preventing master server from replicating table inserts

I have a logging table on the master server that is inserted into very often. I don't need this table replicated to the slave servers, and in fact I already have replicate-ignore-table set on the slaves to ignore it.
However, that only happens after all of those inserts are fetched from the master. I'd like to prevent those inserts from getting sent to the slaves entirely for 2 reasons:
Cut down on network traffic between the servers
I've had cases of the relay log entries being corrupted (and having to skip corrupted entries). Given the quantity of inserts into the logging table, it's always on those inserts (which aren't necessary anyway).
Is it possible to somehow prevent the master from sending back the logs for a specific table? Or, prevent the inserts from showing up in the master's bin-log files? I'm only aware of ignoring databases in the master's bin-log files.
Thanks.
In your code, send "SET SESSION sql_log_bin=0" to MySQL before inserting a logging row. Then set it back to 1 afterward.
This approach gives you fine-grained control over when and when not to binary-log. Only possible drawback is that the database user will need the SUPER privilege.