Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ const (
dbconfigFlags = dbconfigs.DbaConfig
)

func initConfigCmd(subFlags *flag.FlagSet, args []string) error {
subFlags.Parse(args)

// Generate my.cnf from scratch and use it to find mysqld.
mysqld, err := mysqlctl.CreateMysqld(uint32(*tabletUID), *mysqlSocket, int32(*mysqlPort), dbconfigFlags)
if err != nil {
return fmt.Errorf("failed to initialize mysql config: %v", err)
}
defer mysqld.Close()
if err := mysqld.InitConfig(); err != nil {
return fmt.Errorf("failed to init mysql config: %v", err)
}
return nil
}

func initCmd(subFlags *flag.FlagSet, args []string) error {
waitTime := subFlags.Duration("wait_time", 5*time.Minute, "how long to wait for startup")
initDBSQLFile := subFlags.String("init_db_sql_file", "", "path to .sql file to run after mysql_install_db")
Expand Down Expand Up @@ -189,6 +204,8 @@ type command struct {
var commands = []command{
{"init", initCmd, "[-wait_time=5m] [-init_db_sql_file=]",
"Initalizes the directory structure and starts mysqld"},
{"init_config", initConfigCmd, "",
"Initalizes the directory structure, creates my.cnf file, but does not start mysqld"},
{"reinit_config", reinitConfigCmd, "",
"Reinitalizes my.cnf file with new server_id"},
{"teardown", teardownCmd, "[-wait_time=5m] [-force]",
Expand Down
21 changes: 16 additions & 5 deletions go/vt/mysqlctl/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ func binaryPath(root, binary string) (string, error) {
binary, root, strings.Join(subdirs, ","))
}

// Init will create the default directory structure for the mysqld process,
// generate / configure a my.cnf file, install a skeleton database,
// and apply the provided initial SQL file.
func (mysqld *Mysqld) Init(ctx context.Context, initDBSQLFile string) error {
log.Infof("mysqlctl.Init")
// InitConfig will create the default directory structure for the mysqld process,
// generate / configure a my.cnf file.
func (mysqld *Mysqld) InitConfig() error {
log.Infof("mysqlctl.InitConfig")
err := mysqld.createDirs()
if err != nil {
log.Errorf("%s", err.Error())
Expand All @@ -487,7 +486,19 @@ func (mysqld *Mysqld) Init(ctx context.Context, initDBSQLFile string) error {
log.Errorf("failed creating %v: %v", mysqld.config.path, err)
return err
}
return nil
}

// Init will create the default directory structure for the mysqld process,
// generate / configure a my.cnf file install a skeleton database,
// and apply the provided initial SQL file.
func (mysqld *Mysqld) Init(ctx context.Context, initDBSQLFile string) error {
log.Infof("mysqlctl.Init")
err := mysqld.InitConfig()
if err != nil {
log.Errorf("%s", err.Error())
return err
}
// Install data dir.
if err = mysqld.installDataDir(); err != nil {
return err
Expand Down