MySQL replication: adding a new database

Sometimes, you will see MySQL setups where only one database is being replicated. How to add a second database, so that it’s also replicated?

In my.cnf on both servers, add a second database:

Connect to mysql on both servers and add a new database:

Now, restart mysql on both servers and verify that replication works (be careful when restarting if there are any writes to the database; i.e. shutdown the secondary master first, then the primary master – depending on your environment):

After creating/dropping the example table on one server, verify it’s happening on the second server as well:

Don’t forget to add a user with proper privileges, i.e.: