Database Replication - mysql

How do I go about setting up replication on the same mysql server, i.e master and slave both will be the same server?
My requirement is this: I want to replicate few tables on db2 with db1 located on the same server but not all the tables.
I searched the whole the net there are few example like shown here http://www.ruturaj.net/tutorials/mysql/replication/same-server-rewrite-database
but doesn't work for me.
And many examples which explain about the replication setup on two different server
Can anybody please redirect me to the right link, if any available?
Thanks

Not a big deal; just set up two mysql servers on two different port number.
I've used to choose 3306 for master, and 3307 for slave.
Create a new my.cnf for slave server. ( name it my_slave.cnf )
Edit my_slave.cnf : make it using another port, and put slave settings in it.
Duplicate startup script : /etc/init.d/mysqld to /etc/init.d/mysqld_slave
( or add new commands slavestart, slavestop in it. )
And this is my - very - subjective opinion : separate to-be-replicated and not-to-be-replicated on [database] level not on table level. MySQL supports detailed configuration for replication level, but it'll be very complicated and make others confused after months, years later.

Related

percona toolkit Replication filters error

I put the percona toolkit onto my DB hosts so I could try and deal with a problem with mysql going silently out of sync. That is replication seems fine on all nodes. Slave IO running / Slave SQL running and 0 seconds behind master.
I have 4 dbs setup in master/master on the first two, and two slaves, I'm using MariaDB-server-10.0.21 for the MySQL database on each node.
Yet the content of the wiki I run on them seems to go out of sync even with those positive indicators. For instance, you'll create a page, save it, get the thumbs up from the wiki. Then reload the page and the content will be gone! Then you point the wiki config to look at each db one at a time, reload the page. Until you find the db that saved the changes you made.
Then dump that db, stop the slaves on each host one at time and then import that version of the database. It's a real pain!
So I installed the percona toolkit after reading an article on how to solve this problem.
And when I run the pt-table-checksum command I get this error, saying Replication filters are set on these hosts:
[root#db1:~] #pt-table-checksum --replicate=test.checksum --databases=sean --ignore-tables=semaphore localhost
10-17T00:31:11 Replication filters are set on these hosts:
db3
binlog_do_db = jfwiki,jokefire,bacula,mysql
db2
binlog_do_db = jfwiki,jokefire,bacula,mysql
db4
binlog_do_db = jfwiki,jokefire,bacula,mysql
Please read the --check-replication-filters documentation to learn how to solve this problem. at /bin/pt-table-checksum line 9644.
But that EC2 host it claims that it's having trouble contacting equates to my 4th database host. I found out by ssh'ing in as my user to that DNS address. And I have no trouble at all logging into that host on the command line using mysql:
Can someone please explain what does this error mean, and how can I fix the issue? Is there any general advice you can give for mysql replication falling silently out of sync?
Thanks
Some of the pt tools need to create their own database and have it replicated. Your binlog_do_db prevents the extra db from being replicated, hence preventing that tool from working.
While you have the binlog_do removed, see what db it being built. Then add it.

Mysql Replication, 2 databases, 2 ways?

I have 2 MYSQL server.
MySQL#1
and
MySQL#2
MySQL#1 hosts a database which has been replicated thanks to this tutorial https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql to MySQL#2. Let's name this first database DATABASE1
MySQL#2 hosts another database DATABASE2 which has nothing to do with DATABASE1.
Is it possible to replicate as master-slave without creating conflict with the first replication, to let MySQL#1 becoming the slave for MySQL#2 ?
Thanks for any tips.
It is possible. I used to do that myself. There are several ways to do so.
At slave server configuration file, add replicate-ignore-db = DATABASE_YOU_WANT_TO_IGNORE
At master server configuration file, only log the database you want replicate to slave. binlog_do_db = DATABASE_YOU_WANT_TO_REPLICATE
Not only you can specified what database to repliace, you can even specified only what table in particular database that you want to replicate. See also replicate_wild_do_table
Further Reading
Replication Slave Options and Variables
How To Set Up Selective Master Slave Replication in MySQL
Why MySQL’s binlog-do-db option is dangerous

MySQL Master/Master replication working only one way

I have two mysql databases. I want to do a master/master replication.
Replication is working one way. However, the other way it does not. The error states that it can't connect with user 'test#IPADDRESS'.
How can I change the username to repl? Never put in test, so not sure how it even trying to connect with that user. Doesn't exist in the user table either.
You need the CHANGE MASTER TO command (run from the 'slave'). It's the MASTER_USER you're after.

Can mysql replication be configured to prevent drop database being replicated?

Can mysql replication be configured to prevent certain commands being replicated to the slaves.
Imagine a completely invented scenario where someone types
drop database foo;
into the wrong ssh window
(I know, it can never happen)
Currently mysql will replicate that command to the slaves.
Can you block that and so redirect the application server to use on of the slaves and keep systems running.
I fully understand that this question is only one dimension of a DR strategy.
We run mysql 5.5
replicate just one database and do not grant drop database to the user on slave server
replicate-do-db=db01
or replicate table per table:
replicate-do-table=db_name.tbl_name
sorry the poor english

Mysql Replicated database not updating properly

I have been trying to start replication in a mysql database. I followed all the steps from the mysql manual to setup and configure the replication.
http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html
I could start the replication without any trouble. Newly inserted data was replicated properly.
But after a while I observed that though INSERT are working, the UPDATEs are not replicating. So, my replicated database contains data just as it was inserted first time.
My master database is on an UNIX server with MYSQL-5.1.56. The slave is used in Windows using WAMP package with MYSQL 5.5.8. I have also tried a slave with lower version mysql with WAMP5, with same effect.
Please share your ideas and experience on this. Thanks.
I have similar problem. I know it's old thread but it can help others:
link: mysql replication works only if I choose database by USE database
I sorted it out a few months ago. The problem was, I tried to replicate only one single database, and set binlog_do_db and binlog-ignore-db options in master to select only that database. But that left out any statement which was executed without selecting database by USE database, as kayn said. Using replicate-ignore-db and replicate-do-db options in slave would do the same. So I finally fixed it by using the replicate-wild-do-table option in the slave, referenced here. Added the following line in the configuration of the slave server.
replicate-wild-do-table=mydb.%