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

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.