diff --git a/go/cmd/mysqlctl/mysqlctl.go b/go/cmd/mysqlctl/mysqlctl.go index fcdb6d4702f..0c296e78105 100644 --- a/go/cmd/mysqlctl/mysqlctl.go +++ b/go/cmd/mysqlctl/mysqlctl.go @@ -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") @@ -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]", diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index d2024085c9b..081eda91d07 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -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()) @@ -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