Enabling binary logs

  1. Enable binary logging and set the server_id. Open the MySQL config file in your favorite editor and append the following lines. Choose server_id such that it will be unique to each MySQL server in your infrastructure. You can also simply put the log_bin variable in my.cnf without any value. In that case, the binary log is created in the data directory directory and uses hostname as its name.
shell> sudo vi /etc/my.cnf[mysqld]log_bin = /data/mysql/binlogs/server1server_id = 100
  1. Restart the MySQL server:
shell> sudo systemctl restart mysql
  1. Verify that binary logs are created:
mysql> SHOW VARIABLES LIKE 'log_bin%';+---------------------------------+-----------------------------------+| Variable_name                   | Value                             |+---------------------------------+-----------------------------------+ ...

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.