forked from JamesStewy/go-mysqldump
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
235 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
/* | ||
Create MYSQL dumps in Go without the 'mysqldump' CLI as a dependency. | ||
Example | ||
# Example | ||
This example uses the mysql driver (https://github.com/go-sql-driver/mysql) to connect to a mysql instance. | ||
package main | ||
import ( | ||
"database/sql" | ||
"fmt" | ||
"github.com/JamesStewy/go-mysqldump" | ||
"github.com/go-sql-driver/mysql" | ||
) | ||
func main() { | ||
config := mysql.NewConfig() | ||
config.User = "your-user" | ||
config.Passwd = "your-pw" | ||
config.DBName = "your-db" | ||
config.Net = "tcp" | ||
config.Addr = "your-hostname:your-port" | ||
dumpDir := "dumps" // you should create this directory | ||
dumpFilenameFormat := fmt.Sprintf("%s-20060102T150405", dbname) | ||
db, err := sql.Open("mysql", config.FormatDNS()) | ||
if err != nil { | ||
fmt.Println("Error opening database: ", err) | ||
return | ||
} | ||
// Register database with mysqldump. | ||
dumper, err := mysqldump.Register(db, dumpDir, dumpFilenameFormat) | ||
if err != nil { | ||
fmt.Println("Error registering databse:", err) | ||
return | ||
} | ||
// Dump database to file. | ||
resultFilename, err := dumper.Dump() | ||
if err != nil { | ||
fmt.Println("Error dumping:", err) | ||
return | ||
} | ||
fmt.Printf("File is saved to %s", resultFilename) | ||
// Close dumper, connected database and file stream. | ||
dumper.Close() | ||
} | ||
package main | ||
import ( | ||
"database/sql" | ||
"fmt" | ||
"github.com/JamesStewy/go-mysqldump" | ||
"github.com/go-sql-driver/mysql" | ||
) | ||
func main() { | ||
config := mysql.NewConfig() | ||
config.User = "your-user" | ||
config.Passwd = "your-pw" | ||
config.DBName = "your-db" | ||
config.Net = "tcp" | ||
config.Addr = "your-hostname:your-port" | ||
dumpDir := "dumps" // you should create this directory | ||
dumpFilenameFormat := fmt.Sprintf("%s-20060102T150405", dbname) | ||
db, err := sql.Open("mysql", config.FormatDNS()) | ||
if err != nil { | ||
fmt.Println("Error opening database: ", err) | ||
return | ||
} | ||
// Register database with mysqldump. | ||
dumper, err := mysqldump.Register(db, dumpDir, dumpFilenameFormat) | ||
if err != nil { | ||
fmt.Println("Error registering databse:", err) | ||
return | ||
} | ||
// Dump database to file. | ||
resultFilename, err := dumper.Dump() | ||
if err != nil { | ||
fmt.Println("Error dumping:", err) | ||
return | ||
} | ||
fmt.Printf("File is saved to %s", resultFilename) | ||
// Close dumper, connected database and file stream. | ||
dumper.Close() | ||
} | ||
*/ | ||
package mysqldump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.