当前位置: 首页>>代码示例>>Golang>>正文


Golang DSN.Port方法代码示例

本文整理汇总了Golang中github.com/percona/percona-agent/mysql.DSN.Port方法的典型用法代码示例。如果您正苦于以下问题:Golang DSN.Port方法的具体用法?Golang DSN.Port怎么用?Golang DSN.Port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/percona/percona-agent/mysql.DSN的用法示例。


在下文中一共展示了DSN.Port方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getDSNFromUser

func (i *Installer) getDSNFromUser(dsn *mysql.DSN) error {
	// Ask for username
	username, err := i.term.PromptString("MySQL username", dsn.Username)
	if err != nil {
		return err
	}
	dsn.Username = username

	// Ask for password
	var password string
	if i.flags.Bool["plain-passwords"] {
		password, err = i.term.PromptString("MySQL password", "")
	} else {
		password, err = gopass.GetPass("MySQL password: ")
	}
	if err != nil {
		return err
	}
	dsn.Password = password

	// Ask for hostname / socket path
	hostname, err := i.term.PromptStringRequired(
		"MySQL host[:port] or socket file",
		dsn.To(),
	)
	if err != nil {
		return err
	}
	if filepath.IsAbs(hostname) {
		dsn.Socket = hostname
		dsn.Hostname = ""
	} else {
		f := strings.Split(hostname, ":")
		dsn.Hostname = f[0]
		if len(f) > 1 {
			dsn.Port = f[1]
		} else {
			dsn.Port = "3306"
		}
		dsn.Socket = ""
	}
	return nil
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:43,代码来源:mysql.go

示例2: autodetectDSN

func (i *Installer) autodetectDSN(dsn *mysql.DSN) error {
	params := []string{}
	if i.flags.String["mysql-defaults-file"] != "" {
		params = append(params, "--defaults-file="+i.flags.String["mysql-defaults-file"])
	}
	// --print-defaults needs to be last param
	params = append(params, "--print-defaults")
	cmd := exec.Command("mysql", params...)
	byteOutput, err := cmd.Output()
	if err != nil {
		return err
	}
	output := string(byteOutput)
	if i.flags.Bool["debug"] {
		log.Println(output)
	}
	autoDSN := ParseMySQLDefaults(output)
	if i.flags.Bool["debug"] {
		log.Printf("autoDSN: %#v\n", autoDSN)
	}
	// Fill in the given DSN with auto-detected options.
	if dsn.Username == "" {
		dsn.Username = autoDSN.Username
	}
	if dsn.Password == "" {
		dsn.Password = autoDSN.Password
	}
	if dsn.Hostname == "" {
		dsn.Hostname = autoDSN.Hostname
	}
	if dsn.Port == "" {
		dsn.Port = autoDSN.Port
	}
	if dsn.Socket == "" {
		dsn.Socket = autoDSN.Socket
	}
	if dsn.Username == "" {
		user, err := user.Current()
		if err == nil {
			dsn.Username = user.Username
		}
	}
	if i.flags.Bool["debug"] {
		log.Printf("dsn: %#v\n", dsn)
	}
	return nil
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:47,代码来源:mysql.go

示例3: connectMySQL

func (i *Installer) connectMySQL(def *mysql.DSN, creating bool) (mysql.DSN, error) {
	dsn := mysql.DSN{}
	if creating {
		fmt.Println("Specify a root/super MySQL user to create a user for the agent")
	} else if def != nil {
		fmt.Println("Verify the existing MySQL user to use for the agent")
		dsn = *def
		if dsn.Username == "" {
			user, _ := user.Current()
			if user != nil {
				dsn.Username = user.Username
			}
		}
	} else {
		fmt.Println("Specify an existing MySQL user to use for the agent")
	}

CONNECT_MYSQL:
	for {
		username, err := i.term.PromptStringRequired("MySQL username", dsn.Username)
		if err != nil {
			return dsn, err
		}
		dsn.Username = username

		var password string
		if creating {
			password, err = gopass.GetPass("MySQL password: ")
		} else {
			password, err = i.term.PromptString("MySQL password", dsn.Password)
		}
		if err != nil {
			return dsn, err
		}
		dsn.Password = password

		hostname, err := i.term.PromptStringRequired("MySQL host[:port] or socket file", dsn.To())
		if err != nil {
			return dsn, err
		}
		if filepath.IsAbs(hostname) {
			dsn.Socket = hostname
			dsn.Hostname = ""
		} else {
			f := strings.Split(hostname, ":")
			dsn.Hostname = f[0]
			if len(f) > 1 {
				dsn.Port = f[1]
			} else {
				dsn.Port = "3306"
			}
			dsn.Socket = ""
		}

		if err := TestMySQLConnection(dsn); err != nil {
			fmt.Printf("Error connecting to MySQL %s: %s\n", dsn, err)
			again, err := i.term.PromptBool("Try again?", "Y")
			if err != nil {
				return dsn, err
			}
			if !again {
				return dsn, fmt.Errorf("Failed to connect to MySQL")
			}
			continue CONNECT_MYSQL
		}
		fmt.Printf("MySQL connection OK\n")
		break
	}
	return dsn, nil
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:70,代码来源:mysql.go


注:本文中的github.com/percona/percona-agent/mysql.DSN.Port方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。