MCPcopy
hub / github.com/sqlc-dev/sqlc / startMySQLDaemon

Function startMySQLDaemon

cmd/sqlc-test-setup/main.go:645–661  ·  view source on GitHub ↗

startMySQLDaemon starts mysqld_safe in the background and waits for it to accept connections. Extra args (e.g. "--skip-grant-tables") are appended.

(extraArgs ...string)

Source from the content-addressed store, hash-verified

643// startMySQLDaemon starts mysqld_safe in the background and waits for it to
644// accept connections. Extra args (e.g. "--skip-grant-tables") are appended.
645func startMySQLDaemon(extraArgs ...string) error {
646 args := append([]string{"mysqld_safe", "--user=mysql"}, extraArgs...)
647 log.Printf("starting mysql via mysqld_safe %v", extraArgs)
648 cmd := exec.Command("sudo", args...)
649 cmd.Stdout = os.Stderr
650 cmd.Stderr = os.Stderr
651 if err := cmd.Start(); err != nil {
652 return fmt.Errorf("starting mysqld_safe: %w", err)
653 }
654
655 log.Println("waiting for mysql to accept connections")
656 if err := waitForMySQL(30 * time.Second); err != nil {
657 return fmt.Errorf("mysql did not start in time: %w", err)
658 }
659 log.Println("mysql is accepting connections")
660 return nil
661}
662
663// mysqlReady checks if MySQL is running and accepting connections with the expected password.
664func mysqlReady() bool {

Callers 1

startMySQLFunction · 0.85

Calls 1

waitForMySQLFunction · 0.70

Tested by

no test coverage detected