• Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A zero-dependency, high-performance, concurrent mysqldump tool implemented in golang. golang 中实现的零依赖、支持所有类型、 高性能、并发 mysqldump 工具。


mysqldump

简体中文

A zero-dependency,all data types are supported, high-performance, concurrent mysqldump tool implemented in golang.

Features

  • Supports custom Writer: data can be written to any Writer, such as local files, multiple file storage, remote servers, cloud storage, etc. (default console output).
  • Supports all MySQL data types QuickStart.
  • Support Merge Insert Option in Source Greatly improve data recovery performance

QuickStart

Create Table and Insert Test Data

DROP TABLE IF EXISTS `test`;

CREATE TABLE `test` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `char_col` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `varchar_col` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `binary_col` binary(10) DEFAULT NULL,
  `varbinary_col` varbinary(255) DEFAULT NULL,
  `tinyblob_col` tinyblob,
  `tinytext_col` tinytext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `text_col` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `blob_col` blob,
  `mediumtext_col` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `mediumblob_col` mediumblob,
  `longtext_col` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `longblob_col` longblob,
  `enum_col` enum('value1','value2','value3') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `set_col` set('value1','value2','value3') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `bit_col` bit(8) DEFAULT NULL,
  `tinyint_col` tinyint NOT NULL DEFAULT '0',
  `bool_col` tinyint(1) NOT NULL DEFAULT '0',
  `boolean_col` tinyint(1) NOT NULL DEFAULT '0',
  `smallint_col` smallint NOT NULL DEFAULT '0',
  `mediumint_col` mediumint NOT NULL DEFAULT '0',
  `int_col` int NOT NULL DEFAULT '0',
  `integer_col` int NOT NULL DEFAULT '0',
  `bigint_col` bigint NOT NULL DEFAULT '0',
  `float_col` float(8,2) NOT NULL DEFAULT '0.00',
  `double_col` double(8,2) NOT NULL DEFAULT '0.00',
  `decimal_col` decimal(10,2) NOT NULL DEFAULT '0.00',
  `dec_col` decimal(10,2) NOT NULL DEFAULT '0.00',
  `date_col` date DEFAULT NULL,
  `datetime_col` datetime DEFAULT NULL,
  `timestamp_col` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `time_col` time DEFAULT NULL,
  `year_col` year DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `test` VALUES (1,'abc','def',0x61626300000000000000,0x646566,0x74696E79626C6F62,'Hello','World',0x776F726C64,'Medium Text',0x4D656469756D426C6F62,'Long Text',0x4C6F6E67426C6F62,'value2','value1,value3',0x66,-128,1,0,-32768,-8388608,-2147483648,-2147483648,-9223372036854775808,1234.56,1234.56,1234.56,1234.56,'2023-03-17','2023-03-17 10:00:00','2023-03-17 14:04:46','10:00:00',2023);

Dump SQL

import (
	"os"

	"github.com/jarvanstack/mysqldump"
)

func main() {

	dns := "root:rootpasswd@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai"

	f, _ := os.Create("dump.sql")

	_ = mysqldump.Dump(
		dns,                          // DNS
		mysqldump.WithDropTable(),    // Option: Delete table before create (Default: Not delete table)
		mysqldump.WithData(),         // Option: Dump Data (Default: Only dump table schema)
		mysqldump.WithTables("test"), // Option: Dump Tables (Default: All tables)
		mysqldump.WithWriter(f),      // Option: Writer (Default: os.Stdout)
	)
}

Output File dump.sql

-- ----------------------------
-- MySQL Database Dump
-- Start Time: 2023-04-21 14:16:56
-- ----------------------------


USE `dc3`;
DROP TABLE IF EXISTS `test`;
-- ----------------------------
-- Table structure for test
-- ----------------------------
CREATE TABLE IF NOT EXISTS `test` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `char_col` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `varchar_col` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `binary_col` binary(10) DEFAULT NULL,
  `varbinary_col` varbinary(255) DEFAULT NULL,
  `tinyblob_col` tinyblob,
  `tinytext_col` tinytext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `text_col` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `blob_col` blob,
  `mediumtext_col` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `mediumblob_col` mediumblob,
  `longtext_col` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `longblob_col` longblob,
  `enum_col` enum('value1','value2','value3') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `set_col` set('value1','value2','value3') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `bit_col` bit(8) DEFAULT NULL,
  `tinyint_col` tinyint NOT NULL DEFAULT '0',
  `bool_col` tinyint(1) NOT NULL DEFAULT '0',
  `boolean_col` tinyint(1) NOT NULL DEFAULT '0',
  `smallint_col` smallint NOT NULL DEFAULT '0',
  `mediumint_col` mediumint NOT NULL DEFAULT '0',
  `int_col` int NOT NULL DEFAULT '0',
  `integer_col` int NOT NULL DEFAULT '0',
  `bigint_col` bigint NOT NULL DEFAULT '0',
  `float_col` float(8,2) NOT NULL DEFAULT '0.00',
  `double_col` double(8,2) NOT NULL DEFAULT '0.00',
  `decimal_col` decimal(10,2) NOT NULL DEFAULT '0.00',
  `dec_col` decimal(10,2) NOT NULL DEFAULT '0.00',
  `date_col` date DEFAULT NULL,
  `datetime_col` datetime DEFAULT NULL,
  `timestamp_col` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `time_col` time DEFAULT NULL,
  `year_col` year DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;



-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES (1,'abc','def',0x61626300000000000000,0x646566,0x74696E79626C6F62,'Hello','World',0x776F726C64,'Medium Text',0x4D656469756D426C6F62,'Long Text',0x4C6F6E67426C6F62,'value2','value1,value3',0x66,-128,1,0,-32768,-8388608,-2147483648,-2147483648,-9223372036854775808,1234.56,1234.56,1234.56,1234.56,'2023-03-17','2023-03-17 10:00:00','2023-03-17 14:04:46','10:00:00',2023);


-- ----------------------------
-- Dumped by mysqldump2
-- Cost Time: 5.81592ms
-- ----------------------------

Source SQL

import (
	"os"

	"github.com/jarvanstack/mysqldump"
)

func main() {

	dns := "root:rootpasswd@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai"
	f, _ := os.Open("dump.sql")

	_ = mysqldump.Source(
		dns,
		f,
		mysqldump.WithMergeInsert(1000), // Option: Merge insert 1000 (Default: Not merge insert)
		mysqldump.WithDebug(),           // Option: Print execute sql (Default: Not print execute sql)
	)
}

More Repositories

1

markpic

一键下载 markdown 中图片, 并通过 picgo 上传图片到图床并替换链接
Go
55
star
2

marknum

自动生成 markdown 标题序号
Go
32
star
3

ddd_demo

Domain Driven Design demo for golang
Go
29
star
4

pn

PasswordNote是一个密码管理工具, 一键生成各种格式密码, 客户端加密, 服务器只储存hash值, 实现您的密码只有您自己知道, 数据只有您自己能访问, 支持一键免费部署自己的服务器, 实现数据私有化
Go
27
star
5

markdown-resume

Markdown 简历模版, typroa 简历主题, 保证导出 PDF 简历刚好一页
CSS
25
star
6

copy-paste-detector

重复代码检测工具
Go
16
star
7

gitbook-summary

A Gitbook Summary Generator implemented by Golang
Go
15
star
8

huzhu

互助网 (一个基于javaweb技术提供 同校学生互相帮助平台 的网站)
Java
8
star
9

Java-GUI-GreadySnack

Java GUI 贪吃蛇项目,带素材.
Java
7
star
10

pprof-study

本项目是一个 go pprof 实战项目, 下面将手把手带你通过 web, 交互界面, graph图/火焰图 找到性能优化位置并优化代码
Go
7
star
11

gitbook-demo

gitbook-demo
Shell
6
star
12

cf_eth

Crowdfunding system contract based on Ethereum (blockchain)
Solidity
6
star
13

cf_web

Crowdfunding system contract based on Ethereum (blockchain)
Vue
6
star
14

work_summary_generator

Go
6
star
15

NMID_02

NMID的第二阶段考核
Java
5
star
16

dengjiawen8955

5
star
17

javaWeb

javaweb学习阶段的代码同步备份
JavaScript
5
star
18

stogo

连表查询语句一键生成go结构体
Go
5
star
19

huffman-zip-demo

huffman zip demo
Go
5
star
20

elk_alert_dev

5
star
21

goweb

goweb is a web framefork for go
Go
5
star
22

cloud_go_demo

serverless go demo
Dockerfile
5
star
23

gosql

go orm 框架
Shell
5
star
24

etcd-demo

Go
5
star
25

spring

Spring容器学习笔记备份
Java
5
star
26

springmvc

SpringMVC学习笔记备份
Java
5
star
27

nats-demo

Go
5
star
28

go_datastructure_algorithm

datastructure and algorithm by golang
Go
5
star
29

gopl.io

The Go Programming Language source code
Go
5
star
30

git-demo

Go
5
star
31

gocache

高性能分布式kv缓存 gocache
Go
5
star
32

gostl

高性能数据结构和算法标准模板库 类似 C++ STL
Go
5
star
33

go_utils

my useful go utils.
HTML
5
star
34

NMID

用于NMID实验室的作业提交
Java
5
star
35

mybatis

Mybatis学习阶段笔记
Java
5
star
36

proto-demo

makefile of potobuf install compile and use
Makefile
5
star
37

javaweb2

javaweb拓展,比如邮件发送,文件上传等.
Java
5
star
38

protoc_compiler

开箱即用的 protoc 编译环境 + 一键编译的脚本, 开箱即用, 解决编译 pb 文件问题.
Go
5
star
39

template_go

project template_go
Shell
5
star
40

go_work

实验室项目作业提交
Go
5
star
41

c_datastructure_algorithm

DataStructure and algorithm by c
C
5
star
42

json_parse

golang json parse
Shell
5
star
43

vscode

vscode编辑的前端代码备份
HTML
4
star
44

epoll_go

a simple implements of epoll by go syscall.
Go
4
star
45

home

个人主页
CSS
4
star
46

go_static_server

simple implement of static web server (like nginx) with
Go
4
star
47

lru_cache

lru_cache for goland
Go
4
star
48

cicd01

持续集成,测试01
Java
4
star
49

buf_demo

a demo of how to use buf generate protocol buffer file to golang .
4
star
50

template_go_test

template_go_test
Shell
4
star
51

c_tcp_to_http

a simple demo of implements http use tcp proto
C
4
star
52

nmid-end

example for nmid-end repository
4
star
53

java_static_server

a simple demo of implements static web tcp proto
Java
4
star
54

grpc_demo

Here is grpc demo.
Go
4
star
55

jsb-uniapp

剪刀石头布的前端uniapp代码
Vue
4
star
56

Redis

Redis学习笔记代码
Java
4
star
57

java_tcp_to_http

a simple demo of implements http use tcp proto
Java
4
star
58

object_lesson

Java
4
star
59

HOME-Jarvan

Jupyter Notebook
4
star
60

go-start

go过程代码
Go
4
star
61

car_plate

电子车牌信息管理系统
4
star
62

how_to_release_my_package

How to release my go package
Go
4
star
63

springboot

springboot 学习阶段笔记
Java
4
star
64

revert-test

测试 revert 为什么,之前没有生效
4
star
65

epoll_c

a simple implements of epoll by c
C
4
star
66

c_static_server

simple implements of static web server with c
C
4
star
67

JavaLab

重庆邮电大学19中软Java实验课代码+教程
Java
4
star
68

datastructure

Java
4
star
69

jsb

websocket及时高并发聊天框式游戏
Go
4
star
70

go_tcp_to_http

a simple demo of implements http use tcp proto
Go
4
star
71

pages_test

docsifu说明文档测试
4
star
72

java_basic

java基础代码笔记,重helloword到MySQL数据的代码笔记备份
Java
4
star
73

website-view

高性能统计网站 UV 和 PV 统计
JavaScript
3
star
74

bmft-blog

Shell
2
star
75

pr

Punctuation Replace 将英文标点转化为中文标点
Go
2
star
76

evbus

CQRS eventbus golang
Go
1
star
77

university-guide

JavaScript
1
star
78

doc-template

docstify 文档模板
JavaScript
1
star
79

docsify-template

基于 gitbook-summary 自动生成目录的 docsify 模板项目
Makefile
1
star