mysqldump

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2017 License: MIT Imports: 7 Imported by: 4

README

Go MYSQL Dump

Create MYSQL dumps in Go without the mysqldump CLI as a dependancy.

GoDoc

Documentation

Overview

Create MYSQL dumps in Go without the 'mysqldump' CLI as a dependancy.

Example

This example uses the mymysql driver (example 7 https://github.com/ziutek/mymysql) to connect to a mysql instance.

package main

import (
	"database/sql"
	"fmt"
	"github.com/JamesStewy/go-mysqldump"
	"github.com/ziutek/mymysql/godrv"
	"time"
)

func main() {
    // Register the mymysql driver
    godrv.Register("SET NAMES utf8")

    // Open connection to database
    db, err := sql.Open("mymysql", "tcp:host:port*database/user/password")
	if err != nil {
        fmt.Println("Error opening databse:", err)
        return
    }

    // Register database with mysqldump
    dumper, err := mysqldump.Register(db, "dumps", time.ANSIC)
    if err != nil {
    	fmt.Println("Error registering databse:", err)
    	return
    }

    // Dump database to file
    err = dumper.Dump()
    if err != nil {
    	fmt.Println("Error dumping:", err)
    	return
    }

    // Close dumper and connected database
    dumper.Close()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dumper

type Dumper struct {
	// contains filtered or unexported fields
}

Dumper represents a database.

func Register

func Register(db *sql.DB, dir, format string) (*Dumper, error)

Creates a new dumper.

db: Database that will be dumped (https://golang.ir/pkg/database/sql/#DB).
dir: Path to the directory where the dumps will be stored.
format: Format to be used to name each dump file. Uses time.Time.Format (https://golang.ir/pkg/time/#Time.Format). format appended with '.sql'.

func (*Dumper) Close

func (d *Dumper) Close() error

Closes the dumper. Will also close the database the dumper is connected to.

Not required.

func (*Dumper) Dump

func (d *Dumper) Dump() error

Creates a MYSQL Dump based on the options supplied through the dumper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL