0. precondition
a) install mysql 5.7, for detail please refer my blog post.
1. login mysql and check the variables to see if the binlog has been enabled.
mysql -h 127.0.0.1 -uroot -proot show variables like '%log_bin%';
we can see, the log_bin is disabled.
2. Turn on mysql log_bin
sudo vim /etc/mysql/conf.d/mysql.cnf
add the following config segment at the end of the file
# ---------------------------------------------- # Enable the binlog for replication & CDC # ---------------------------------------------- # Enable binary replication log and set the prefix, expiration, and log format. # The prefix is arbitrary, expiration can be short for integration tests but would # be longer on a production system. Row-level info is required for ingest to work. # Server ID is required, but this will vary on production systems server-id = 223344 log_bin = /var/lib/mysql/mysql-bin expire_logs_days = 3 binlog_format = row
#Mysql Packet Size may need to be re-configured. MySQL may have, by default, a ridiculously low allowable packet size.
#To increase it, you’ll need to have the property max_allowed_packet set to a higher number, say 1024M. max_allowed_packet=1024M
this configration means:
a) the server id is unique for each server, an is required for log_bin capture, it should be a numeric number equal or greater than 0, in my instance I set it to 223344, this number should be unique in the whole cluster. seems it's a good idea to set it as the ip
address number of the machine install. I fact I have do this in my real production enviroment.
b) the path of the log_bin, this is required to define the storage location fo the log_bin.
c) the log_bin retention time, in my case, I set it to 3 days.
d. the bin_log format, we should define it as row.
The whole definition file in my case is:
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M skip-host-cache skip-name-resolve #datadir=/var/lib/mysql #socket=/var/lib/mysql/mysql.sock #secure-file-priv=/var/lib/mysql-files user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #log-error=/var/log/mysqld.log #pid-file=/var/run/mysqld/mysqld.pid # ---------------------------------------------- # Enable the binlog for replication & CDC # ---------------------------------------------- # Enable binary replication log and set the prefix, expiration, and log format. # The prefix is arbitrary, expiration can be short for integration tests but would # be longer on a production system. Row-level info is required for ingest to work. # Server ID is required, but this will vary on production systems server-id = 223344 log_bin = /var/lib/mysql/mysql-bin expire_logs_days = 3 binlog_format = row #Mysql Packet Size may need to be re-configured. MySQL may have, by default, a ridiculously low allowable packet size. #To increase it, you’ll need to have the property max_allowed_packet set to a higher number, say 1024M. max_allowed_packet=1024M #set default charactor set to utf-8 character-set-server=utf8 collation-server=utf8_unicode_ci