+var (
+ flag_debug = flag.Bool("debug", false, "Enabling debug logging")
+ flag_defaults_file = flag.String("defaults-file", "", "Provide a defaults-file to use to connect to MySQL")
+ flag_help = flag.Bool("help", false, "Provide some help for "+lib.MyName())
+ flag_host = flag.String("host", "", "Provide the hostname of the MySQL to connect to")
+ flag_port = flag.Int("port", 0 , "Provide the port number of the MySQL to connect to (default: 3306)") /* deliberately 0 here, defaults to 3306 elsewhere */
+ flag_socket = flag.String("socket", "", "Provide the path to the local MySQL server to connect to")
+ flag_password = flag.String("password", "", "Provide the password when connecting to the MySQL server")
+ flag_user = flag.String("user", "", "Provide the username to connect with to MySQL (default: $USER)")
+ flag_version = flag.Bool("version", false, "Show the version of "+lib.MyName())
+ cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
+
+ re_valid_version = regexp.MustCompile(`^(5\.[67]\.|10\.[01])`)
+)
+
+// Connect to the database with the given defaults-file, or ~/.my.cnf if not provided.
+func connect_by_defaults_file( defaults_file string ) *sql.DB {
+ var err error
+ var dbh *sql.DB
+ lib.Logger.Println("connect_by_defaults_file() connecting to database")
+
+ dbh, err = mysql_defaults_file.OpenUsingDefaultsFile(sql_driver, defaults_file, "performance_schema")
+ if err != nil {
+ log.Fatal(err)
+ }
+ if err = dbh.Ping(); err != nil {
+ log.Fatal(err)
+ }
+
+ // deliberately limit the pool size to 5 to avoid "problems" if any queries hang.
+ dbh.SetMaxOpenConns(5) // hard-coded value!
+
+ return dbh
+}
+
+// connect to MySQL using various component parts needed to make the dsn
+func connect_by_components( components map[string]string ) *sql.DB {