Book Image

MySQL 8 Cookbook

By : Karthik Appigatla
Book Image

MySQL 8 Cookbook

By: Karthik Appigatla

Overview of this book

MySQL is one of the most popular and widely used relational databases in the World today. The recently released MySQL 8 version promises to be better and more efficient than ever before. This book contains everything you need to know to be the go-to person in your organization when it comes to MySQL. Starting with a quick installation and configuration of your MySQL instance, the book quickly jumps into the querying aspects of MySQL. It shows you the newest improvements in MySQL 8 and gives you hands-on experience in managing high-transaction and real-time datasets. If you've already worked with MySQL before and are looking to migrate your application to MySQL 8, this book will also show you how to do that. The book also contains recipes on efficient MySQL administration, with tips on effective user management, data recovery, security, database monitoring, performance tuning, troubleshooting, and more. With quick solutions to common and not-so-common problems you might encounter while working with MySQL 8, the book contains practical tips and tricks to give you the edge over others in designing, developing, and administering your database effectively.
Table of Contents (20 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Setting up replication filters


You can control which tables or databases are to be replicated. On the master, you can control which databases to log changes for by using the --binlog-do-db and --binlog-ignore-db options to control binary logging, as mentioned in Chapter 6, Binary Logging. The better way is to control on the slave side. You can execute or ignore statements received from the master by using--replicate-* options or dynamically by creating replication filters.

How to do it...

To create a filter, you need to execute the CHANGE REPLICATION FILTER statement.

Replicate a database only

Assume that you want to replicate db1 and db2 only. Use the following statement to create the replication filter.

mysql> CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db1, db2);

Note that you should specify all the databases inside parentheses.

Replicate specific tables

You can specify the tables you want to be replicated using REPLICATE_DO_TABLE:

mysql> CHANGE REPLICATION FILTER REPLICATE_DO_TABLE = ...