Skip to content

Commit 3bcfd7a

Browse files
committed
Add "init_config" option to mysqlctl.
1 parent a140329 commit 3bcfd7a

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

go/cmd/mysqlctl/mysqlctl.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ const (
5050
dbconfigFlags = dbconfigs.DbaConfig
5151
)
5252

53+
func initConfigCmd(subFlags *flag.FlagSet, args []string) error {
54+
subFlags.Parse(args)
55+
56+
// Generate my.cnf from scratch and use it to find mysqld.
57+
mysqld, err := mysqlctl.CreateMysqld(uint32(*tabletUID), *mysqlSocket, int32(*mysqlPort), dbconfigFlags)
58+
if err != nil {
59+
return fmt.Errorf("failed to initialize mysql config: %v", err)
60+
}
61+
defer mysqld.Close()
62+
if err := mysqld.InitConfig(); err != nil {
63+
return fmt.Errorf("failed to init mysql config: %v", err)
64+
}
65+
return nil
66+
}
67+
5368
func initCmd(subFlags *flag.FlagSet, args []string) error {
5469
waitTime := subFlags.Duration("wait_time", 5*time.Minute, "how long to wait for startup")
5570
initDBSQLFile := subFlags.String("init_db_sql_file", "", "path to .sql file to run after mysql_install_db")
@@ -189,6 +204,8 @@ type command struct {
189204
var commands = []command{
190205
{"init", initCmd, "[-wait_time=5m] [-init_db_sql_file=]",
191206
"Initalizes the directory structure and starts mysqld"},
207+
{"init_config", initConfigCmd, "",
208+
"Initalizes the directory structure, creates my.cnf file, but does not start mysqld"},
192209
{"reinit_config", reinitConfigCmd, "",
193210
"Reinitalizes my.cnf file with new server_id"},
194211
{"teardown", teardownCmd, "[-wait_time=5m] [-force]",

go/vt/mysqlctl/mysqld.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,10 @@ func binaryPath(root, binary string) (string, error) {
466466
binary, root, strings.Join(subdirs, ","))
467467
}
468468

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

492+
// Init will create the default directory structure for the mysqld process,
493+
// generate / configure a my.cnf file install a skeleton database,
494+
// and apply the provided initial SQL file.
495+
func (mysqld *Mysqld) Init(ctx context.Context, initDBSQLFile string) error {
496+
log.Infof("mysqlctl.Init")
497+
err := mysqld.InitConfig()
498+
if err != nil {
499+
log.Errorf("%s", err.Error())
500+
return err
501+
}
491502
// Install data dir.
492503
if err = mysqld.installDataDir(); err != nil {
493504
return err

0 commit comments

Comments
 (0)