Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added features #2

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build Binary
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true

- name: Build Linux Binary
run: |
GOOS=linux GOARCH=amd64 go build -v -o bin/go-parse-linux-amd64 ./cmd

- name: Build MacOS Binary
run: |
GOOS=darwin GOARCH=amd64 go build -v -o bin/go-parse-darwin-amd64 ./cmd

- name: Upload Linux Binary
uses: actions/upload-artifact@v4
with:
name: go-parse-linux-amd64
path: bin/go-parse-linux-amd64

- name: Upload MacOS Binary
uses: actions/upload-artifact@v4
with:
name: go-parse-darwin-amd64
path: bin/go-parse-darwin-amd64

- name: Test
run: go test -v ./...
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore binary files in bin directory
bin/*

# Keep the bin directory structure
!bin/.gitkeep
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Go-parse
# go-parse

is a Go cli MySQL binlog parser
A MySQL binary log parser utility.

## Usage

```Go
./go-parse -h
Usage: go-parse -file <binlog file> [-offset <offset>] [-logPosition <log position>] [-listPositions] [-stopAtNext]
Usage: cmd -file <binlog file> [-all] [-offset <offset>] [-logPosition <log position>] [-listPositions] [-stopAtNext] [-showStats] [-verbose] [-schema <schema file>]
-all
Parse entire binlog file
-file string
Binlog file to parse
-listPositions
Expand All @@ -13,8 +17,14 @@ Usage: go-parse -file <binlog file> [-offset <offset>] [-logPosition <log positi
Log position to start from (use -1 to ignore) (default -1)
-offset int
Starting offset (use -1 to ignore) (default -1)
-schema string
MySQL schema dump file to load
-showStats
Show operation statistics by database and table
-stopAtNext
Stop at the next log position
-verbose
Show detailed position information for each event



Expand Down Expand Up @@ -50,7 +60,55 @@ Error code: 0
Schema: mysql
Query: CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types';

reached log position 10093
found next event at position 10559 (previous events ended at 10559)

./go-parse -file tests/mysql-bin.000012 -schema schema/sbtest-schema-only.sql -logPosition 123 -stopAtNext
=== PreviousGTIDsEvent ===
Date: 2024-11-04 21:18:19
Log position: 194
Event size: 71
Previous GTID Event: 5133d310-9498-11ef-9f1b-0242ac190003:1-11538

found next event at position 194 (previous events ended at 194)

./go-parse -file tests/mysql-bin.000012 -schema schema/sbtest-schema-only.sql -logPosition 194 -stopAtNext
=== GTIDEvent ===
Date: 2024-11-04 21:18:19
Log position: 259
Event size: 65
Commit flag: 0
GTID_NEXT: 5133d310-9498-11ef-9f1b-0242ac190003:11539
LAST_COMMITTED: 0
SEQUENCE_NUMBER: 1
Immediate commmit timestamp: 0 (<n/a>)
Orignal commmit timestamp: 0 (<n/a>)
Transaction length: 0
Immediate server version: 0
Orignal server version: 0

found next event at position 259 (previous events ended at 259)
./go-parse -file tests/mysql-bin.000012 -schema schema/sbtest-schema-only.sql -logPosition 259 -stopAtNext
=== QueryEvent ===
Date: 2024-11-04 21:18:19
Log position: 333
Event size: 74
Slave proxy ID: 8082
Execution time: 0
Error code: 0
Schema: sbtest
Query: BEGIN

found next event at position 333 (previous events ended at 333)
./go-parse -file tests/mysql-bin.000012 -schema schema/sbtest-schema-only.sql -logPosition 333 -stopAtNext
=== RowsQueryEvent ===
Date: 2024-11-04 21:18:19
Log position: 397
Event size: 64
Query: UPDATE sbtest20 SET k=k+1 WHERE id=50431

found next event at position 397 (previous events ended at 397)

./go-parse -file tests/mysql-bin.000001 -all
```

## Using mysqlbinlog
Expand Down Expand Up @@ -108,20 +166,25 @@ DELIMITER ;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
```

## To build

```bash
To build:
## Build Instructions

Build for your current platform:
```
go build -o go-parse
```

FreeBSD:
```
env GOOS=freebsd GOARCH=amd64 go build .
```

On Mac:
```
env GOOS=darwin GOARCH=amd64 go build .
```

Linux:
```
env GOOS=linux GOARCH=amd64 go build .
```

Expand Down
Empty file added bin/.gitkeep
Empty file.
Loading
Loading