I’ve been doing some investigation into properly configuring MySQL replication.

From what I understand after reading the documentation, you can only replicate specific databases, and each database name must be specified: In the master configuration, in order for the relevant database writes to be written to the binary logs, and in the slave configuration, in order to replay those logs onto the slave.

Is this correct, or is it possible to configure MySQL to replicate any and all databases?


To answer your question about how MySQL replicates all databases, here is how it works...

  • Master has Binary Logging enabled
  • Master records completed SQL Statements
  • Master will inject 'USE dbname;' among the SQL Statements it records
  • Slave connects to Master (IO Thread)
  • Slave IO Thread requests next SQL statement from the Binary Logs
  • Slave IO Thread copies it to its Relay Logs
  • Slave SQL Thread Processes its Relay Log Entries FIFO (Queue)

Once USE dbname; is issued out of the relay logs, multiple SQL statements will be processes chronologically until another USE dbname; (a different database) is issued from the Relay Logs.

To see this, pick any Binary Log (except the Current One) on the Master, and run this:

mysqlbinlog binarylogname > SQLStatements.sql

To see all the binary logs and the current binary log on the Master, run these:


Long story short: By default, all DBs are replicated due to the USE dbname; command within the binary logs on the master and the relay logs on the slave.

Abdul's answer shows how to filter in or filter out databases from being processed by the slave.

| improve this answer | |

Yes, you can replicate all databases from master to slave.

But sometimes we don't prefer that Mysql databases should be replicated due to security reasons, because all the user related information will also be available to the slave. That can cause security breaches.

You can set which database should be replicated and which one should not by using options in the configuration file.

   replicate-ignore-db=db_name  and replicate-do-db=db_name

It also depends on which type of replication you are using, like statement based or row based.

Please see:


| improve this answer | |
  • This partially answers my question, but leads to the obvious next question: Okay, so how do I indicate to MySQL that it should replicate every database, with the exception of the mysql database, without manually specifying the name of every database? – Abraham Vegh Dec 8 '11 at 7:37
  • 1
    If don't specify database name it will itself replicate all the database including Mysql. – Abdul Manaf Dec 8 '11 at 8:36

From what I have understood from RolandoMySQLDBA answer is you just add to your my.cnf replicate-ignore-db=mysql to skip mysql system database replication.

| improve this answer | |
  • Doesn't really add much to the existing answer, does it? – mustaccio Sep 17 '16 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.