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 ¶
Types ¶
type Dumper ¶
type Dumper struct {
// contains filtered or unexported fields
}
Dumper represents a database.
func Register ¶
Creates a new dumper.
db: Database that will be dumped (https://golang.org/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.org/pkg/time/#Time.Format). format appended with '.sql'.
Click to show internal directories.
Click to hide internal directories.