func dumpSchema(db *sql.DB, dumpdir string, schema string) {
	dir := path.Join(dumpdir, schema)
	var err error
	err = os.Mkdir(dir, dirPerms)
	checkErr(err)
	var ignore string
	var stmt string
	err = db.QueryRow("show create schema "+addQuotes(schema)).Scan(&ignore, &stmt)
	checkErr(err)
	file := path.Join(dir, schema+sqlExtension)
	err = ioutil.WriteFile(file, []byte(stmt+";\n"), filePerms)
	checkErr(err)
}
dumpSchema creates a file with the schema creation statement.
package main
import (
	"database/sql"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"time"
)
const (
	stamp        = "20060102150405"
	dirPerms     = 0755
	filePerms    = 0644
	sqlExtension = ".sql"
)
func startDump(dir string, dbi *mysqlCredentials) {
	dumpdir := path.Join(dir, dbi.host+"_dump"+time.Now().Format(stamp))
	fmt.Println("Dumping to:", dumpdir)
	fmt.Println()
	db, err := dbi.connect()
	defer db.Close()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	db.SetMaxIdleConns(0)
	db.SetMaxIdleConns(1)
	schemas := schemaList(db)
	err = os.MkdirAll(dumpdir, dirPerms)
	checkErr(err)
	count := 0
	total := 0
	fmt.Println()
	for _, schema := range schemas {
		total++
		fmt.Print(schema, ": ")
		dumpSchema(db, dumpdir, schema)
		count = dumpTables(db, dumpdir, schema)
		total = total + count
		fmt.Print(count, " tables, ")
		count = dumpProcs(db, dumpdir, schema)
		total = total + count
		fmt.Print(count, " procedures, ")
		count = dumpFuncs(db, dumpdir, schema)
		total = total + count
		fmt.Print(count, " functions, ")
		count = dumpTriggers(db, dumpdir, schema)
		total = total + count
		fmt.Print(count, " triggers, ")
		count = dumpViews(db, dumpdir, schema)
		total = total + count
		fmt.Print(count, " views\n")
	}
	fmt.Println()
	fmt.Println(total, "total objects dumped")
}
func schemaList(db *sql.DB) []string {
	rows, err := db.Query("show databases")
	checkErr(err)
	var schemas []string
	var database string
	for rows.Next() {
		err = rows.Scan(&database)
		checkErr(err)
		if database != "mysql" && database != "information_schema" && database != "performance_schema" {
			schemas = append(schemas, database)
		}
	}
	return schemas
}