Friday, March 18, 2016

brewing mysql / binlog reader

Here's what I did to set up MySQL 5.6 on my Mac in binlog row mode, prepping to talk to Aurora.
+1 for brew services!

Install and Test

brew install mysql56
brew tap homebrew/services
brew services start mysql56

mysqladmin -uroot create mh
mysql -uroot

Find my.cnf

/usr/local/bin/mysqld --verbose --help 2>/dev/null | grep -A 1 "Default options" 
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

Configuring binary logging

$ cat /usr/local/etc/my.cnf 
[mysqld]
log-bin=mysql-bin
binlog_format=row
server-id=1235

binlog status

Restart mysql and you can see the logs and current position.

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       143 |
| mysql-bin.000002 |       120 |

+------------------+-----------+
mysql> show master status;
+----------------+----------+-
| File           | Position | 
+----------------+----------+- . . . 
| mysql-bin.000002 |     1309 

+----------------+----------+-

Tailing the binlog


mysqlbinlog --read-from-remote-server --host=localhost  mysql-bin.000001 -uroot -v --stop-never

Insert some data like this

mysql> insert into t values(99);

and you'll see it come out like this

# at 1309
#160318 11:40:42 server id 1235 end_log_pos 1379 CRC32 0xaf303ba0 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1458326442/*!*/;
BEGIN
/*!*/;
# at 1379
#160318 11:40:42 server id 1235 end_log_pos 1421 CRC32 0xb302b235 Table_map: `mh`.`t` mapped to number 70
# at 1421
#160318 11:40:42 server id 1235 end_log_pos 1461 CRC32 0x4d9e5013 Write_rows: table id 70 flags: STMT_END_F

BINLOG '
qkvsVhPTBAAAKgAAAI0FAAAAAEYAAAAAAAEAAm1oAAF0AAEDAAE1sgKz
qkvsVh7TBAAAKAAAALUFAAAAAEYAAAAAAAEAAgAB//5jAAAAE1CeTQ==
'/*!*/;
### INSERT INTO `mh`.`t`
### SET
###   @1=99
# at 1461
#160318 11:40:42 server id 1235  end_log_pos 1492 CRC32 0x94dcc720 Xid = 73
COMMIT/*!*/;


blogodex = {"toc" : "MySQL binlog", "idx" : ["MySQL","binlog","configuration"]};

No comments: