// VtMysqlRoot returns the root for the mysql distribution, which
// contains bin/mysql CLI for instance.
490957
func VtMysqlRoot() (string, error) {
	// if the environment variable is set, use that
	if root := os.Getenv("VT_MYSQL_ROOT"); root != "" {
		return root, nil
	}

	// otherwise let's use VTROOT
	root, err := VtRoot()
	if err != nil {
		return "", errors.New("VT_MYSQL_ROOT is not set and could not be guessed from the executable location. Please set $VT_MYSQL_ROOT")
	}
	return root, nil
}
1232708
func (s *MerkleStoreImpl) refreshRoot(m libkb.MetaContext) error {
	q := libkb.NewHTTPArgs()
	// The user lookup here is unnecessary. It is done because that is what is
	// easy with MerkleClient.  The user looked up is you if known, otherwise
	// arbitrarily t_alice.  If t_alice is removed, this path will break.
	uid := s.G().GetMyUID()
	if len(uid) == 0 {
		// Use t_alice's uid.
		uid = libkb.TAliceUID
	}
	q.Add("uid", libkb.UIDArg(uid))
	_, err := s.G().MerkleClient.LookupUser(m, q, nil)
	return err
}
83534
func MysqlHostname(tablet *topodatapb.Tablet) string {
	if tablet.MysqlHostname == "" {
		return tablet.Hostname
	}
	return tablet.MysqlHostname
}
548824
func MySQLToType(mysqlType, flags int64) (typ querypb.Type, err error) {
	result, ok := mysqlToType[mysqlType]
	if !ok {
		return 0, fmt.Errorf("unsupported type: %d", mysqlType)
	}
	return modifyType(result, flags), nil
}
1090518
func (p *MySQLPrivilege) UserPrivilegesTable() [][]types.Datum {
	var rows [][]types.Datum
	for _, user := range p.User {
		rows = appendUserPrivilegesTableRow(rows, user)
	}
	return rows
}
464483
func (c *Ctrie) rdcssRoot(old *iNode, expected *mainNode, nv *iNode) bool {
	desc := &iNode{
		rdcss: &rdcssDescriptor{
			old:      old,
			expected: expected,
			nv:       nv,
		},
	}
	if c.casRoot(old, desc) {
		c.rdcssComplete(false)
		return atomic.LoadInt32(&desc.rdcss.committed) == 1
	}
	return false
}
458365
func MysqlPort(tablet *topodatapb.Tablet) int32 {
	if tablet.MysqlHostname == "" {
		return tablet.PortMap["mysql"]
	}
	return tablet.MysqlPort
}
113766
func NewSqlVm(sqlText string) (*SqlVm, error) {

	stmt, err := expr.ParseSqlVm(sqlText)
	if err != nil {
		return nil, err
	}
	m := &SqlVm{
		Statement: stmt,
	}
	switch v := stmt.(type) {
	case *expr.SqlSelect:
		m.Keyword = lex.TokenSelect
		m.sel = v
	case *expr.SqlInsert:
		m.Keyword = lex.TokenInsert
		m.ins = v
	case *expr.SqlDelete:
		m.Keyword = lex.TokenDelete
		m.del = v
	}
	return m, nil
}
818187
func (mysqld *Mysqld) InitConfig(cnf *Mycnf) error {
	log.Infof("mysqlctl.InitConfig")
	err := mysqld.createDirs(cnf)
	if err != nil {
		log.Errorf("%s", err.Error())
		return err
	}
	root, err := vtenv.VtRoot()
	if err != nil {
		log.Errorf("%s", err.Error())
		return err
	}

	// Set up config files.
	if err = mysqld.initConfig(root, cnf, cnf.path); err != nil {
		log.Errorf("failed creating %v: %v", cnf.path, err)
		return err
	}
	return nil
}
659457
func (d *Datum) GetMysqlJSON() json.BinaryJSON {
	return json.BinaryJSON{TypeCode: byte(d.i), Value: d.b}
}
589095
func (s Storage) recordModuleRoot(dir, root string) error {
	rec := moduleRecord{
		Dir:  dir,
		Root: root,
	}

	return s.recordModule(rec)
}
67690
func SetMysqlPort(tablet *topodatapb.Tablet, port int32) {
	if tablet.MysqlHostname == "" || tablet.MysqlHostname == tablet.Hostname {
		tablet.PortMap["mysql"] = port
	}
	// If it's the legacy form, preserve old behavior to prevent
	// confusion between new and old code.
	if tablet.MysqlHostname != "" {
		tablet.MysqlPort = port
	}
}
1260575
func (s *Restore) CARoot(r *structs.CARoot) error {
	// Insert
	if err := s.tx.Insert(caRootTableName, r); err != nil {
		return fmt.Errorf("failed restoring CA root: %s", err)
	}
	if err := indexUpdateMaxTxn(s.tx, r.ModifyIndex, caRootTableName); err != nil {
		return fmt.Errorf("failed updating index: %s", err)
	}

	return nil
}
776386
func (ndb *nodeDB) SaveEmptyRoot(version int64) error {
	return ndb.saveRoot([]byte{}, version)
}
747273
func Open(dsn string) (*Adapter, error) {
	var err error

	adapter := &Adapter{
		Adapter: &sql.Adapter{
			Config: &sql.Config{
				Placeholder:   "?",
				EscapeChar:    "`",
				IncrementFunc: incrementFunc,
				ErrorFunc:     errorFunc,
			},
		},
	}
	adapter.DB, err = db.Open("mysql", dsn)

	return adapter, err
}
1348085
func goVClose(pCursor unsafe.Pointer) *C.char {
	vtc := lookupHandle(uintptr(pCursor)).(*sqliteVTabCursor)
	err := vtc.vTabCursor.Close()
	if err != nil {
		return mPrintf("%s", err.Error())
	}
	return nil
}
375215
func setupMySQLTLSConfig(tlsCaFile string) error {
	rootCertPool := x509.NewCertPool()

	pem, err := ioutil.ReadFile(tlsCaFile)
	if err != nil {
		return err
	}

	if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
		return err
	}

	err = mysql.RegisterTLSConfig(mysqlTLSKey, &tls.Config{
		RootCAs: rootCertPool,
	})
	if err != nil {
		return err
	}

	return nil
}