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

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

Related

Setting up MySQL (Master-Slave) replication with all ready configured databases/tables

I am trying to configure MySQL databases using the Master-Slave replication. Before I realized that I had to set up my environment using this replication, I already have 2 separate servers running their own MySQL DB. Each of these servers are configured the exact same. The MySQL DB are configured with hundreds of tables.
Is there a way that i can set up (Master-Slave) Replication using the configured DB's? Or will i have to start from scratch and configure the replication first and then load in all the DB tables?
You can delete all data from one of the servers. Remaining one with the data will be your Master. Then use mysqldump to backup all the data and insert it to the slave.
Take a look for the detailed instructions on the page below:
https://livecaller.io/blog/how-to-set-up-mysql-master-slave-replication/
If the data is exactly same in both the MySQL database then you can start master slave replication, but you need to be sure that the data is same. MySQL will not check that, and if there is some discrepancy in the primary key then it will throw error immediately after next DML statement.
To be on a safer side, drop the database from one server, and restore it using the MySQL dump of another server. This will give the surety that database is same on both the server.
Take the reference from the below link to establish replication between two MySQL servers.
https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

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.%

Two mysql servers using same database

I have a MySQL database running on our server at this location.
However, the internet connection at this location is slow (Especially when several users are connected remotely).
We also have a remote web server on a very fast internet connection.
Can I run another MySQL server on the remote server and still be able to run queries and updates on it?
I want to have two servers because
- Users at this location can connect via lan (fast)
- Users working remotely can connect to synced remote server (fast)
Is this possible? From what I understand replication does not work this way. What is replication used for then? Backups?
Thanks for your help!
[Edit]
After doing some more reading, I am a little worried about setting up multi-master replication due to the fact that I had not considered multi-master when designing the database and conflicts could be an issue.
The good news though is that most time consuming operations are queries not updates.
And, I found out that there is a driver that handles master-slave connections.
http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.html
That way writes will be sent to the master and reads can come from the faster connection.
Has anyone tried doing this before? My one concern is that if I update to the master, then run a query expecting to see the update on the slave, will it be there right away? Or will the slow connection make this solution just as slow as using the master for both read and write?
What you're asking, I believe, is called Multi-Master Replication, by which both servers serve as replication masters to each other. Changes on either server become replicated back to the other as soon as possible. MySQL can be configured to do it, however I'm not sure how the differences in speed would affect your performance and data integrity.
http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-replication-multi-master.html

MySQL replication best practices

I'm setting up MySQL replication via binlog. It's a master / slave setup.
I have a few questions on how to do this the best way.
Should information_schema be replicated, if yes/no, why?
Should mysql db be replicated, if yes/no, why?
If it all should be replicated, no binlog-do-db needs to be set?
Cheers.
No, Information Schema should NEVER be replicated. This is meta data about your tables, dbs, routines, triggers, etc. Let the server populate it's own information_schema.
mysql db is fine to replicate, especially in the instance where you will be setting up a number of users. If your master fails, you will need the same user information available on your slave server in order to fail over to it. If that should occur, you need to have the same privileges available.
List only the database you want replicated with binlog-do-db. If you don't list any, everything will be replicated by default.
No. need to replicate information schema read this for detail https://dev.mysql.com/doc/refman/5.0/en/information-schema.html
Yes you can because mysql database contains all user credentials so in order to have a backup of users you can replicate it.
Yes use binlog-do-db to replicate selected databases otherwise everything will be replicated if nothing mentioned.

MySQL database replication

This is the scenario:
I have a MySQL server with a database, let's call it consolidateddb. This database a consolidation of several tables from various databases
I have another MySQL server, with the original databases, these databases are production databases and are updates daily.
The company wants to copy each update/insert/delete on each table in the production databases to the corresponding tables in consolidateddb.
Would replication accomplish that? I know that replication is done on a databas to database, but not on tables that belong to different databases to one target database.
I hope my explanation was clear. Thanks.
Edit: Would a recursive copy of all tables inn each database to the single slave work? Or is it an ugly solution?
To clear up some things, let's name things accordingly to current mysql practice. A database is a database server. A schema is a database instance. A database server can have multiple schemas. Tables live within a schema.
Replication will help you if you want to duplicate schemas or tables as they are defined on the master/production server. The replication works by shipping a binary log of all the sql statements that are run on the master to the slave which dutifully runs them as if they run sequentially on itself.
You can choose to replicate all data, or you can choose some of the schemas or even just some of the tables.
You can not choose tables from different schemas and have them replicated into one schema, a table belongs to a specific schema.
By the way, important notice. A replication server can not be a slave to multiple masters. You could mimic this using federated tables, but that would never copy the data to the consolidation server, just show them as if the data from different servers were on one server.
The bonus of replication is that your consolidation server will more or less have updated data all the time.
You could take the binary logs from each of the masters, parse them with mysqlbinlog and then run that into the consolidated machine.
Something very approximately like:
mysqlbinlog [binary log files] | mysql -h consolidated
you'd need some kind of simple application (I suspect it could be done in bash if you needed) to wrap the logic.
Check out Replicating Different Databases to Different Slaves, see if it helps you in any way.
MySQL statement-based replication (basic replication) works by running the exact same statements that were run on the master on the slave. This includes information about what database the table was in.
I don't think MySQL provides any built-in way to move replication statements between databases (i.e. "insert into db1.table1 ..." -> "insert into db2.table1"). You may be able to trick it by manually altering the replication logs on the fly, but it wouldn't be out-of-the-bod MySQL replication.
You might be able to pull it off with MySQL Proxy
You may want to check out the maatkit toolkit. It's a free download and has a host of tools that specialize in optimizing things like archiving tables. I've used it on past projects to duplicate certain data to another DB, etc. You can do it based on time or any other number of factors.
To the best of my knowledge you can set up replication (MySQL 4+) and in the my.cnf file have the slave either only process certain tables or have the master log only certain tables, either way will solve your problem.
Here is a guide to some techniques:
http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html
I have very few problems with replication set-up, all my problems came trying to sync DBs, especially after a reboot etc.